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.5.tar.gz (4.0 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.5-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mcp_adapter-0.0.5.tar.gz
Algorithm Hash digest
SHA256 af1cbef8bff0d85497fd7c74d671d80d58f85a88316abfdf44bd93ea2520958f
MD5 2cf745c16b7c70c617e2b87bf9276b97
BLAKE2b-256 40a6675d800aa2e27923df0b832fe181c512cc7f13a071fe33bfe7afe27241f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_adapter-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5090cce90b79562ee17f8c9559019b2caf765a1e0b13ba2e13a2593bfeac1715
MD5 87ce0ac10b2791fc90296b02906daf91
BLAKE2b-256 86fa663fef76114d8e16103b5d374c953b1797c9684721b93e7d149454ced080

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