MCP Client Patterns
HTTP JSON-RPC Call (simple, no SDK needed)
async function callMcpTool(
serverUrl: string,
toolName: string,
args: Record<string, unknown>
): Promise<string> {
const response = await fetch(`${serverUrl}/mcp`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
id: Date.now(),
method: 'tools/call',
params: { name: toolName, arguments: args }
}),
signal: AbortSignal.timeout(30_000), // 30s timeout
});
const data = await response.json();
if (data.error) throw new Error(data.error.message);
return data.result?.content?.[0]?.text ?? '';
}
// Usage
const summary = await callMcpTool(
'http://localhost:3003',
'claude_summarize',
{ content: longText, format: 'bullets' }
);
List Available Tools
const response = await fetch(`${serverUrl}/mcp`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} })
});
const { result } = await response.json();
console.log(result.tools.map(t => t.name));
Julia's MCP Call Map
| Caller |
Server |
Tool |
| Orchestrator |
bridge:3001 |
telegram_get_pending, telegram_send_reply |
| Orchestrator |
cowork-mcp:3003 |
claude_task, claude_summarize |
| Frontend |
bridge:3001 |
get_messages, get_system_status |
1---2name: mcp-client-patterns3description: Connecting to MCP servers, tool invocation, session management. Use when the orchestrator or any agent needs to call tools on an MCP server (bridge, cowork-mcp).4---56# MCP Client Patterns78## HTTP JSON-RPC Call (simple, no SDK needed)9```ts10async function callMcpTool(11 serverUrl: string,12 toolName: string,13 args: Record<string, unknown>14): Promise<string> {15 const response = await fetch(`${serverUrl}/mcp`, {16 method: 'POST',17 headers: { 'Content-Type': 'application/json' },18 body: JSON.stringify({19 jsonrpc: '2.0',20 id: Date.now(),21 method: 'tools/call',22 params: { name: toolName, arguments: args }23 }),24 signal: AbortSignal.timeout(30_000), // 30s timeout25 });26 const data = await response.json();27 if (data.error) throw new Error(data.error.message);28 return data.result?.content?.[0]?.text ?? '';29}3031// Usage32const summary = await callMcpTool(33 'http://localhost:3003',34 'claude_summarize',35 { content: longText, format: 'bullets' }36);37```3839## List Available Tools40```ts41const response = await fetch(`${serverUrl}/mcp`, {42 method: 'POST',43 headers: { 'Content-Type': 'application/json' },44 body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/list', params: {} })45});46const { result } = await response.json();47console.log(result.tools.map(t => t.name));48```4950## Julia's MCP Call Map51| Caller | Server | Tool |52|--------|--------|------|53| Orchestrator | bridge:3001 | `telegram_get_pending`, `telegram_send_reply` |54| Orchestrator | cowork-mcp:3003 | `claude_task`, `claude_summarize` |55| Frontend | bridge:3001 | `get_messages`, `get_system_status` |