MCPClient Python Application

by spirita1204

294 downloads
Not rated
GitHub

About

implementation for interacting between an MCP server and an Ollama model

Details

Author
spirita1204
Downloads
294
Categories
Other, AI

- Asynchronous communication using asyncio
- Connects to both Python and JavaScript server scripts
- Dynamically fetches and interacts with server tools
- Command-line chat interface for conversational queries
- Extracts and executes JSON tool calls from responses
- Loads environment variables from a .env file

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name MCPClient Python Application
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Clone or download the script, install dependencies (pip install -r requirements.txt), create a .env file with environment variables (e.g., BASE_URL and MODEL), then run python client.py <server_script_path> where the server script can be a .py or .js file.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mcpclient python application": {
            "mcp-client-spirita1204": {
                "command": "python",
                "args": [
                    "client.py",
                    "<server_script_path>"
                ]
            }
        }
    }
}

McpServers

{
    "mcp-client-spirita1204": {
        "command": "python",
        "args": [
            "client.py",
            "<server_script_path>"
        ]
    }
}

MCPClient Python Application

This is a Python client application designed to interact with an MCP (Model Context Protocol) server.

Features

- Asynchronous Communication: Uses asyncio for non-blocking communication between the client and server. - Customizable Server Scripts: The client can connect to both Python and JavaScript-based server scripts. - Tool Management: Dynamically fetches and interacts with tools available on the connected server. - Chat Interface: Provides a simple command-line interface to interact with the server in a conversational format. - Tool Integration: Supports extracting JSON-formatted tool calls from server responses and executing them. - Environment Variable Loading: Supports loading environment variables from a .env file using the dotenv package.

Requirements

- Python 3.7 or higher - asyncio library (included with Python) - requests for HTTP requests to the server - mcp (custom library for handling MCP communication) - dotenv for environment variable management

Setup

1. Clone the repository (or download the script files) to your local machine. 2. Install required dependencies: ``bash pip install -r requirements.txt 1. Create a .env file in the root directory to load necessary environment variables. For example: ` BASE_URL=http://localhost:11434 MODEL=llama3.2 ` 2. Run the client with the path to the server script: `bash python client.py <server_script_path> ` The server script can be a Python .py or JavaScript .js file.

How It Works

1. Connecting to the MCP Server: The client connects to the server via standard input/output channels, using the provided script (
.py or .js). 2. Processing Queries: The client sends user queries to the server and receives responses. Available tools are listed and can be called directly from the assistant’s replies. 3. Tool Execution: If a response contains a valid tool call (in JSON format), the client extracts the call and triggers the respective tool on the server. 4. Interaction: The client interacts with the server in a conversational format, displaying results from server tools and continuing the conversation.

Example Workflow

1. The user enters a query like:
`bash Question: What is the weather today? `` 2. The client sends the query to the server, which responds with available tools and information. 3. If the server suggests using a weather tool, the client executes the tool with the necessary parameters and shows the result. 4. The client continues the conversation based on the new information returned by the tool. https://github.com/furey/mongodb-lens
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.