ototree

ototree

by otoTree
Exposes a local MCP server via Flask for integration with platforms like Coze, Dify, and FastGPT.

Local MCP Server Integration with Flask

Overview

The mcp - client project is designed to expose a local MCP server using Flask, enabling users to set up their own intranet penetration. This allows platforms like Coze, Dify, and FastGPT to interact with local resources seamlessly.

Tools

Prerequisites

Ensure that the uv tool is installed. Refer to the official documentation for installation instructions.

Project Directory Setup

Create a new directory for the project and navigate into it:

uv init project - name
cd project - name

Replace project - name with your desired project name.

Virtual Environment Setup

Create and activate a virtual environment using uv:

uv venv
.venv\Scripts\activate

For Linux or macOS:

source .venv/bin/activate

Dependency Installation

Install the project dependencies listed in pyproject.toml:

uv install

Configuration

Server Configuration

Configure server details in mcp_server.json. Example configuration:

{
    "mcpServers": {
        "weather": {
            "desc": "获取天气信息以及相关工具",
            "command": "uv",
            "args": [
                "--directory",
                "D:\\project_python\\MCP\\weather",
                "run",
                "weather.py"
            ]
        },
        "filesystem": {
            "desc": "文件管理",
            "command": "uv",
            "args": [
                "--directory",
                "D:\\project_python\\MCP\\mcp - server\\filesystem",
                "run",
                "main.py"
            ]
        }
    }
}

Environment Variables

Copy .env.example to .env:

cp .env.example .env

Fill in the environment variables in .env:

ANTHROPIC_API_KEY = 123456
SECRET_KEY = gduifgashjb8t3961jhgsdghf

Ensure .env is in .gitignore:

.env

Usage

Running the Server

Start the server by running:

python server.py

API Endpoints

List Tools on a Server

Send a POST request to /list_tool:

{
    "server_name": "weather",
    "secret_key": "gduifgashjb8t3961jhgsdghf"
}

Call a Tool on a Server

Send a POST request to /call_tool:

{
    "server_name": "weather",
    "tool_name": "get_weather",
    "args": {
        "city": "Beijing"
    },
    "secret_key": "gduifgashjb8t3961jhgsdghf"
}

List All Servers

Send a POST request to /list_server:

{
    "secret_key": "gduifgashjb8t3961jhgsdghf"
}

List Files in a Directory

Send a POST request to /list_files:

{
    "secret_key": "gduifgashjb8t3961jhgsdghf"
}

Get File Download Link

Send a GET request to /get_download_link/<secret_key>/<filename>:

curl http://localhost:5000/get_download_link/gduifgashjb8t3961jhgsdghf/example.txt

Notes

Server Configuration

Ensure paths and commands in mcp_server.json are correct to avoid service startup issues.

Environment Variable Security

Keep .env secure to prevent leakage of sensitive information like API keys.

Debug Mode

Use app.run(debug = True, ssl_context = 'adhoc') for development. Avoid using debug mode in production.

Self-Signed Certificate Issues

Self-signed certificates may cause issues on cloud platforms like Coze. Consider using a trusted SSL certificate for deployment.

Recommended Solutions

  • Local Development: Continue using self-signed certificates and debug mode.
  • Cloud Deployment: Use a trusted SSL certificate from a Certificate Authority (CA) like Let's Encrypt.

Features & Capabilities

Categories
mcp_server model_context_protocol python flask api_integration local_server

Implementation Details

Stats

0 Views
3 GitHub Stars

Repository Info

otoTree Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300