Skip to content

MCP tools (remote server)

Connect to the public DeepWiki MCP server (https://mcp.deepwiki.com/mcp), ask the model to answer a question about the MCP TypeScript SDK using the ask_question tool, and assert the response mentions stdio.

The official SDKs split into two camps:

  • Hosted MCP (OpenAI, Anthropic, xAI): hand the provider a public URL; the provider calls DeepWiki. No MCP client lib needed — but only works with public, provider-reachable servers.
  • Client-side MCP (Google, OpenRouter): install @modelcontextprotocol/sdk, create an MCPClient, connect, list tools, wrap them per-SDK, manage the tool-call loop yourself. Google alone needs 4 extra imports. OpenRouter needs all that plus a hand-rolled response loop.

Four different integration patterns for the same protocol.

connectMcp() is always client-side — one call, no extra packages, works with any server (local, private, or public):

import { complete, connectMcp, createEngine } from '@combycode/llm-sdk';
const engine = createEngine();
const mcp = await connectMcp({ url: 'https://mcp.deepwiki.com/mcp', name: 'deepwiki' }, { engine });
const { text } = await complete({
model: process.env.LLM_MODEL!,
apiKey: process.env.LLM_API_KEY,
prompt: 'What transport protocols does the modelcontextprotocol/typescript-sdk support? Use the DeepWiki MCP server.',
tools: mcp.tools,
maxTokens: 1024,
});
await mcp.close();
import { complete, connectMcp, createEngine } from '@combycode/llm-sdk';

// The differentiator: ONE connectMcp() works for EVERY provider — client-side,
// zero extra deps, identical code. (Official: OpenAI/Anthropic/xAI hand a URL to
// a HOSTED connector; Google must install @modelcontextprotocol/sdk + wrap an MCP
// Client; OpenRouter installs the MCP sdk AND hand-writes the tool loop. Four
// stories.) Because ours is client-side it also works with local/private/stdio
// servers the hosted providers can't reach.
const engine = createEngine(); // bare engine just carries the MCP fetch (DeepWiki is no-auth)
const mcp = await connectMcp({ url: 'https://mcp.deepwiki.com/mcp', name: 'deepwiki' }, { engine });

const t0 = performance.now();
const { text } = await complete({
  model: process.env.LLM_MODEL!,
  apiKey: process.env.LLM_API_KEY,
  prompt:
    'What transport protocols does the modelcontextprotocol/typescript-sdk support? Use the DeepWiki MCP server.',
  tools: mcp.tools,
  maxTokens: 1024,
});

await mcp.close();
console.log(JSON.stringify({ result: text.trim(), ms: Math.round(performance.now() - t0) }));

connectMcp() opens an MCP session over HTTP (Streamable HTTP transport). It fetches the server’s tool list via tools/list, wraps each as a defineTool-compatible descriptor with an execute that calls tools/call. The resulting mcp.tools array is passed to complete() as normal client-side tools. Because it is client-side, it works with stdio servers and private/local servers that hosted connectors cannot reach.