
mcp client
An MCP client for Node.js.
Repository Info
About This Server
An MCP client for Node.js.
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
MCP Client
An MCP client for Node.js.
TIP
This client has been tested with FastMCP.
Why?
- MCP TypeScript SDK provides a client for the MCP protocol, but it's a little verbose for my taste. This client abstracts away some of the lower-level details (like pagination, Zod schemas, etc.) and provides a more convenient API.
- The MCP protocol follows some REST-like naming conventions, like
listToolsandreadResource, but those names look a bit awkward in TypeScript. This client uses more typical method names, likegetToolsandgetResource.
Usage
Creating a client
import { MCPClient } from "mcp-client";
const client = new MCPClient({
name: "Test",
version: "1.0.0",
});
Connecting using Streaming HTTP
await client.connect({
type: "httpStream",
url: "http://localhost:8080/mcp",
});
Connecting using stdio
await client.connect({
type: "stdio",
args: ["--port", "8080"],
command: "node",
env: {
PORT: "8080",
},
});
Connecting using SSE (Deprecated)
await client.connect({
type: "sse",
url: "http://localhost:8080/sse",
});
Pinging the server
await client.ping();
Calling a tool
const result = await client.callTool({
name: "add",
arguments: { a: 1, b: 2 },
});
Calling a tool with a custom result schema
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(),
}),
),
}),
},
);
Listing tools
const tools = await client.getAllTools();
Listing resources
const resources = await client.getAllResources();
Reading a resource
const resource = await client.getResource({ uri: "file:///logs/app.log" });
Getting a prompt
const prompt = await client.getPrompt({ name: "git-commit" });
Listing prompts
const prompts = await client.getAllPrompts();
Setting the logging level
await client.setLoggingLevel("debug");
Completing a prompt
const result = await client.complete({
ref: { type: "ref/prompt", name: "git-commit" },
argument: { name: "changes", value: "Add a new feature" },
});
Listing resource templates
const resourceTemplates = await client.getAllResourceTemplates();
Receiving logging messages
client.on("loggingMessage", (message) => {
console.log(message);
});
NOTE
Equivalent to setNotificationHandler(LoggingMessageNotificationSchema, (message) => { ... }) in the MCP TypeScript SDK.
Quick Start
Clone the repository
git clone https://github.com/punkpeye/mcp-clientInstall dependencies
cd mcp-client
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.