Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Prerequisites

  • Python 3.9+
  • Anthropic API Key

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

Option 1: Setup with uv (Recommended)

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
python main.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

Linting and Typing Check

There are no lint or type checks implemented.

Following observations were made during the local development using

  1. Python version 3.12.0
  2. mcp version 2.1.1
  3. fastmcp module version 4.0.0

The import statement in mcp_server.py was updated to

from fastmcp import FastMCP
from pydantic import Field

mcp = FastMCP("DocumentMCP")
  • Use following commands to run the mcp server and inspector
uv run mcp_server.py 
  • followed by another command in separate terminal *
uv run fastmcp dev inspector mcp_server.py  

Run & Fixes

Follow these steps to run main.py with the example prompt used for tool-calling and to understand recent fixes applied in this repo.

  • Setup virtualenv and activate it (if not already):

     python -m venv .venv
     source .venv/bin/activate
  • Install dependencies (use your preferred method):

     pip install -r requirements.txt
     # or
     uv pip install -e .
  • Run main.py (the CLI will prompt for input):

     uv run main.py
  • Example prompt to trigger tool calling:

     What is the content of report.pdf
    
  • Fixes applied in this workspace (already committed):

    • core/tools.py: converted inputSchemainput_schema and isErroris_error to match Pydantic/typed-field names.
    • core/claude.py: removed unsupported temperature keyword from messages.create(...) call to match the installed Anthropics client API.
  • Troubleshooting tips:

    • If you see an AttributeError on model fields (e.g., 'Tool' object has no attribute 'inputSchema'), switch camelCase references to snake_case (e.g., input_schema).
    • If you see TypeError: unexpected keyword argument, inspect the client method signature and remove unsupported params.
    • Search the repo for common camelCase names:
       rg "inputSchema|isError|temperature" || grep -R "inputSchema\|isError\|temperature" .

About

From Anthropic skilljar learning

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages