Skip to main content
Glama

MCP Chat

MCP Chat is a command-line interface application that enables interactive chat capabilities with AI models through the Anthropic API. The application supports document retrieval, command-based prompts, and extensible tool integrations via the MCP (Model Control Protocol) architecture. https://anthropic.skilljar.com/claude-with-the-anthropic-api/

Tools: Model-controlled: Claude decides when to call these. Results are used by Claude. Used for:

  • giving additional funcationality to Claude

Resources: App-controlled: Our app decides when to call thse. Results are primarily used by our app. Used for

  • Getting data into our app

  • Adding context to messages

Prompts: User-controlled: The user decides when to use these. Used for:

  • Predefined workflows to run based on user input, like slash command, button click, or menu option.

Prerequisites

  • Python 3.9+

  • Anthropic API Key

Related MCP server: MCP Chat Server

Setup

Step 1: Configure the environment variables

  1. Create or edit the .env file in the project root and verify that the following variables are set correctly:

ANTHROPIC_API_KEY=""  # Enter your Anthropic API secret key

Step 2: Install dependencies

uv is a fast Python package installer and resolver.

  1. Install uv, if not already installed:

pip install uv
  1. Create and activate a virtual environment:

uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:

uv pip install -e .
  1. Run the project

uv run main.py

Option 2: Setup without uv

  1. Create and activate a virtual environment:

python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:

pip install anthropic python-dotenv prompt-toolkit "mcp[cli]==1.8.0"
  1. Run the project

uv run main.py

OR

python main.py

Prompt: What is the contents of the report.pdf document? Here's what happens behind the scenes:

Your application uses the client to get available tools

  1. These tools are sent to Claude along with your question

  2. Claude decides to use the read_doc_contents tool

  3. Your application uses the client to execute that tool

  4. The result is returned to Claude, who then responds to you

  5. The client acts as the bridge between your application logic and the MCP server's functionality, making it easy to integrate powerful tools into your AI workflows.

To see the MCP Web inspector to debug your mcp_server.py changes run:

uv run mcp dev mcp_server.py

Usage

Basic Interaction

Simply type your message and press Enter to chat with the model.

Document Retrieval

Use the @ symbol followed by a document ID to include document content in your query:

> Tell me about @deposition.md

Commands

Use the / prefix to execute commands defined in the MCP server:

> /summarize deposition.md

Commands will auto-complete when you press Tab.

Development

Adding New Documents

Edit the mcp_server.py file to add new documents to the docs dictionary.

Implementing MCP Features

To fully implement the MCP features:

  1. Complete the TODOs in mcp_server.py

  2. Implement the missing functionality in mcp_client.py. You can run the client:

uv run mcp_client.py

This will connect to your MCP server and print out the available tools. You should see output showing your tool definitions, including descriptions and input schemas.

Linting and Typing Check

There are no lint or type checks implemented.

Related MCP Connectors

Related MCP Servers