Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Conversation

allenzhou101
Copy link
Contributor

@allenzhou101 allenzhou101 commented Feb 18, 2025

This PR relies on the quickstart-resources PR merging first as it links to the Python and Typescript MCP clients.

Specifically, this change will add a section to the Quickstart For Client Developers focused on Node/Typescript

Screenshot 2025-02-17 at 4 50 27 PM

Motivation and Context

MCP Client tutorials exist for Python and Java but not Node. Including this section improves the DX for MCP Client developers.

How Has This Been Tested?

The code in this tutorial was validated via connecting to multiple MCP Servers locally.

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Fixes #103

@allenzhou101 allenzhou101 changed the title Mcp client typescript Add Guide to Creating an MCP Client in Typescript Feb 18, 2025
@allenzhou101 allenzhou101 changed the title Add Guide to Creating an MCP Client in Typescript Add Tutorial to Creating an MCP Client in Typescript Feb 18, 2025
@allenzhou101 allenzhou101 changed the title Add Tutorial to Creating an MCP Client in Typescript Add Tutorial for Creating an MCP Client in Typescript Feb 18, 2025
@dsp-ant dsp-ant self-requested a review March 10, 2025 10:44
Copy link
Member

@dsp-ant dsp-ant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just got around reviewing this. Thank you so much for taking care of this. this is a great improvement.

- Mac or Windows computer
- Node.js 16 or higher installed
- Latest version of `npm` and `npx` installed
- Anthropic API key (Claude)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably clarify that others can be used, but this tutorial uses Claude.

import readline from "readline/promises";
import dotenv from "dotenv";

dotenv.config();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a comment that these specific bits are for?

Comment on lines +528 to +563
async connectToServer(serverScriptPath: string) {
try {
const isJs = serverScriptPath.endsWith(".js");
const isPy = serverScriptPath.endsWith(".py");
if (!isJs && !isPy) {
throw new Error("Server script must be a .js or .py file");
}
const command = isPy
? process.platform === "win32"
? "python"
: "python3"
: process.execPath;

this.transport = new StdioClientTransport({
command,
args: [serverScriptPath],
});
this.mcp.connect(this.transport);

const toolsResult = await this.mcp.listTools();
this.tools = toolsResult.tools.map((tool) => {
return {
name: tool.name,
description: tool.description,
input_schema: tool.inputSchema,
};
});
console.log(
"Connected to server with tools:",
this.tools.map(({ name }) => name)
);
} catch (e) {
console.log("Failed to connect to MCP server: ", e);
throw e;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specialcasing .js or .py might give the impression that this is the standard behaviour. I would prefer if we assume we read the configs from a json or yaml file.

@dsp-ant dsp-ant merged commit adc70f0 into modelcontextprotocol:main Mar 10, 2025
tzolov pushed a commit to tzolov/modelcontextprotocol-docs that referenced this pull request Mar 20, 2025
…otocol#147)

* Add mcp-client-typescript quickstart guide

* Improve client running explanation, best practices, etc.

* Set new python mcp client github link

* Only call list tools at initialization

* Add package.json and tsconfig.json setup section

---------

Co-authored-by: David Soria Parra <167242713+dsp-ant@users.noreply.github.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Quickstart for client development using Node
2 participants