Skip to main content

基于FastAPI,以类集成的方式快速实现mcp tools以及服务挂载

Project description

mcp-adapter

  • 对mcp sdk的二次封装
  • 以python类继承的方式,非侵入式封装function到mcp tool的转化
  • FastAPI支持,快速挂载在FastAPI服务中

Getting started

1. 继承McpServerAdapterBase,实现功能

from mcp_adapter.core.server_base import McpServerAdapterBase


class MockMcpServerSse(McpServerAdapterBase):

    name = 'MockMcpServerSse'

    description = 'MockMcpServerSse Service'

    @staticmethod
    def add(a: int, b: int) -> int:
        """Add two numbers"""
        return a + b

    @staticmethod
    def sub(a: int, b: int) -> int:
        """Sub two numbers"""
        return a - b

    @staticmethod
    def multiply(a: int, b: int) -> int:
        """Multiply two numbers"""
        return a * b


class MockMcpServerHttpStreamable(McpServerAdapterBase):

    name = 'MockMcpServerHttpStreamable'

    description = 'MockMcpServerHttpStreamable Service'

    @staticmethod
    def add(a: int, b: int) -> int:
        """Add two numbers"""
        return a + b

    @staticmethod
    def sub(a: int, b: int) -> int:
        """Sub two numbers"""
        return a - b

    @staticmethod
    def multiply(a: int, b: int) -> int:
        """Multiply two numbers"""
        return a * b

2. 在FastAPI项目中加载mcp server

请参考: 脚手架项目

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_adapter-0.0.3.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_adapter-0.0.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file mcp_adapter-0.0.3.tar.gz.

File metadata

  • Download URL: mcp_adapter-0.0.3.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.12

File hashes

Hashes for mcp_adapter-0.0.3.tar.gz
Algorithm Hash digest
SHA256 680dd222e556f3cf963f7639e5bec20ab624999abf72450fa86fb0c84fd5d124
MD5 135cfb4043f73e27d78543ef339964fc
BLAKE2b-256 d60f8def35db0f1bed5f177655c63e4307e68e8f6e84ed5b37b437337eba666b

See more details on using hashes here.

File details

Details for the file mcp_adapter-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_adapter-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 42c557cf54d1574c8ebbb4bb6a0c7985042288c722ff5b1e59e544e4fb2f11b3
MD5 107c94111eae47536cf28cba52fee382
BLAKE2b-256 b74a9e4781150ba23eaf43da8694e474230cec7769738ed3e59080b91f37433b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page