An MCP client for Node.js.
An MCP client for Node.js.
[!TIP] This client has been tested with FastMCP.
listTools
and readResource
, but those names look a bit awkward in TypeScript. This client uses more typical method names, like getTools
and getResource
.import { MCPClient } from "mcp-client";
const client = new MCPClient({
name: "Test",
version: "1.0.0",
});
stdio
await client.connect({
type: "stdio",
args: ["--port", "8080"],
command: "node",
env: {
PORT: "8080",
},
});
await client.connect({
type: "sse",
url: "http://localhost:8080/sse",
});
await client.ping();
const result = await client.callTool({
name: "add",
arguments: { a: 1, b: 2 },
});
const result = await client.callTool(
{
name: "add",
arguments: { a: 1, b: 2 },
},
{
resultSchema: z.object({
content: z.array(
z.object({
type: z.literal("text"),
text: z.string(),
}),
),
}),
},
);
const tools = await client.getAllTools();
const resources = await client.getAllResources();
const resource = await client.getResource({ uri: "file:///logs/app.log" });
const prompt = await client.getPrompt({ name: "git-commit" });
const prompts = await client.getAllPrompts();
await client.setLoggingLevel("debug");
const result = await client.complete({
ref: { type: "ref/prompt", name: "git-commit" },
argument: { name: "changes", value: "Add a new feature" },
});
const resourceTemplates = await client.getAllResourceTemplates();
client.on("loggingMessage", (message) => {
console.log(message);
});
[!NOTE] Equivalent to
setNotificationHandler(LoggingMessageNotificationSchema, (message) => { ... })
in the MCP TypeScript SDK.
{ "mcpServers": { "mcp-client": { "command": "node", "args": [ "--port", "8080" ] } } }
Related projects feature coming soon
Will recommend related projects based on sub-categories