A TypeScript client implementation for the Model Context Protocol (MCP) using Server-Sent Events (SSE) transport.
This client connects to MCP servers over HTTP using Server-Sent Events (SSE) and allows AI assistants like Claude to interact with custom tools exposed by the server. Unlike the standard examples that typically use stdio for local server communication, this client demonstrates how to implement remote server connections via SSE.
- Connect to MCP servers over HTTP using SSE transport
- Discover and execute tools exposed by the server
- Integrate with Claude or other AI assistants via the Anthropic API
- Maintain interactive chat sessions with tool execution
- Node.js (v16 or newer)
- npm or yarn
- An Anthropic API key
# Clone the repository
git clone https://github.com/tyfeng1997/mcp-client.git
cd mcp-client
# Install dependencies
npm install
# Build the TypeScript code
npm run build
Create a .env
file in the root directory with your Anthropic API key:
ANTHROPIC_API_KEY=your_api_key_here
To start the client and connect to an MCP server:
node build/index.js http://localhost:3001/sse
Replace http://localhost:3001/sse
with the SSE endpoint URL of your MCP server.
Once connected, the client will start an interactive chat session where you can:
- Type natural language queries
- The client will send these to Claude
- If Claude decides to use tools, the client will execute them through the MCP server
- Results will be displayed in the conversation
- Type 'quit' to exit
- "Not connected" error: Make sure the server is running and the SSE endpoint is accessible. Also verify that your client code properly awaits the connection promise.
- Timeout errors: The server might be taking too long to respond. Check server logs for any issues.
- Tool execution errors: Ensure the tool parameters being passed match what the server expects.
This client is designed to work with the MCP server available at tyfeng1997/mcp-server, which provides a weather information service over SSE. You can also connect it to any other MCP-compliant server that supports SSE transport.
To modify the client:
- Make changes to the TypeScript files
- Rebuild with
npm run build
- Run the client to test your changes
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.