Fire in da houseTop Tip:Paying $100+ per month for Perplexity, MidJourney, Runway, ChatGPT and other tools is crazy - get all your AI tools in one site starting at $15 per month with Galaxy AI Fire in da houseCheck it out free

mcp-client

MCP.Pizza Chef: punkpeye

The mcp-client is a Node.js client for the Model Context Protocol (MCP) that abstracts low-level protocol details, providing a simpler and more convenient API for developers. It improves on the MCP TypeScript SDK by offering more natural method names and handling complexities like pagination and schema validation internally. Designed for seamless integration, it supports communication via stdio and is tested with FastMCP, making it ideal for building MCP-enabled applications in Node.js environments.

Use This MCP client To

Simplify MCP protocol integration in Node.js applications Manage MCP tool and resource interactions with easy API calls Connect to MCP servers using stdio communication Abstract pagination and schema validation in MCP workflows Develop MCP-enabled agents and copilots in JavaScript/TypeScript

README

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 listTools and readResource, but those names look a bit awkward in TypeScript. This client uses more typical method names, like getTools and getResource.

Usage

Creating a client

import { MCPClient } from "mcp-client";

const client = new MCPClient({
  name: "Test",
  version: "1.0.0",
});

Connecting using stdio

await client.connect({
  type: "stdio",
  args: ["--port", "8080"],
  command: "node",
  env: {
    PORT: "8080",
  },
});

Connecting using SSE

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.

mcp-client FAQ

How do I install the mcp-client in my Node.js project?
You can install it via npm or yarn using 'npm install mcp-client' or 'yarn add mcp-client'.
Does mcp-client support communication over stdio?
Yes, mcp-client supports stdio communication and can connect to MCP servers using this method.
How does mcp-client simplify MCP protocol usage?
It abstracts lower-level details like pagination and Zod schema validation, providing more intuitive method names and a cleaner API.
Is mcp-client compatible with other MCP servers?
While tested with FastMCP, mcp-client follows MCP protocol standards and should work with any compliant MCP server.
Can I use mcp-client with TypeScript?
Yes, mcp-client is designed for Node.js and works well with TypeScript, offering type safety and autocompletion.
What are typical connection options for mcp-client?
It supports various connection types including stdio, TCP, and potentially others depending on server capabilities.
Where can I find documentation and examples for mcp-client?
Documentation and usage examples are available on the GitHub repository README and linked MCP protocol resources.