examples/MCP-tools Public
import { Client } from "@modelcontextprotocol/sdk/client/index.js";import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";import { createServer, type ServerOptions } from "../src/server.ts";// A client connected to a fresh server over an in-memory transport: the whole MCP exchange,// without HTTP.export async function connect(options: ServerOptions = {}): Promise<Client> { const [clientSide, serverSide] = InMemoryTransport.createLinkedPair(); await createServer(options).connect(serverSide); const client = new Client({ name: "test", version: "0.0.0" }); await client.connect(clientSide); return client;}// The text of a tool result's first content block.export function textOf(result: object): string { const [first] = ("content" in result ? result.content : []) as { type: string; text?: string }[]; return first?.type === "text" ? (first.text ?? "") : "";}