About Mcp client example
A sample command-line chat application that combines the Anthropic API with an MCP client and server. It demonstrates connecting to an MCP server, retrieving its tools, and using them in an assistant chat.
Key features
- 01Command-line chat application
- 02Anthropic API integration
- 03MCP client and server connection
- 04Retrieves server tool information
Use cases
- 01Trying an Anthropic-powered MCP chat
- 02Inspecting tools exposed by an MCP server
- 03Exploring a sample MCP client flow
MCP support
The client connects to a configured MCP server and retrieves its tool information for use in the chat.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMcp client example
This is a sample CLI chat application for an AI assistant using the Anthropic API in conjunction with an MCP client and MCP server.
Reference: For Client Developers - Model Context Protocol
Anthropic API: Initial setup - Anthropic Messages - Anthropic
System diagram
Sequence diagram
sequenceDiagram
participant User
participant MCPClient
participant AnthropicAPI
participant MCPServer
User->>MCPClient: Run
MCPClient->>MCPServer: Connect and get tool info
MCPServer-->>MCPClient: Tool info
loop Chat loop (until 'quit' is entered)
User->>MCPClient: Enter query
MCPClient->>AnthropicAPI: Send query
AnthropicAPI-->>MCPClient: AI response
alt When tool usage is required
MCPClient->>MCPServer: Call tool
MCPServer-->>MCPClient: Tool execution result
MCPClient->>AnthropicAPI: Send query again including tool result
AnthropicAPI-->>MCPClient: Final response
end
MCPClient-->>User: Display response
end
User->>MCPClient: Enter 'quit'
MCPClient->>MCPServer: Disconnect
MCPClient-->>User: Exit
Setup
pnpm install
.env
ANTHROPIC_API_KEY=your-api-key
MCP_SERVER_SCRIPT_PATH=/path/to/mcp-server.js
Build
pnpm build
Run
pnpm start
Output example
Use this mcp server https://github.com/t-shiratori/time-tools-mcp-server
mcp-client-example $ pnpm start
> [email protected] start /path/to/mcp-client-example
> node build/index.js
Example MCP Server running on stdio
Connected to server with tools: [ 'get_current_date_time', 'get_elapsed_time' ]
MCP Client Started!
Type your queries or 'quit' to exit.
🖌 Query: Hello
Hello! I'm here to assist you. I can help you with tasks related to date and time, such as getting the current date and time or calculating the elapsed time between two dates.
Is there something specific you'd like to know about dates or times today?
🖌 Query: What time is it?
I can check the current date and time for you.
[Calling tool get_current_date_time with args {}]
Based on the given timestamp, the time is 10:37:19 AM on May 6th, 2025.
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.