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.4.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.4-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_adapter-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 c75e5e0951fb02d55cdd62cef680a08a4e2a15b3dc0f4534ce3453808160c9a1
MD5 32a1a40002f3b3805664ca2eae83bd1b
BLAKE2b-256 831ec773f9ce1c486c30f2efcec1ae44a58ca8f924753e97c57c2886a01c0299

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_adapter-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4a68a73c97be57e4a86529863708dd5541d9036f420b3e284e5271ff29053f44
MD5 2ba3bdcbfc900e42001a19dd4702c338
BLAKE2b-256 a4c2fb43ca4626d8ce017256bd4de95f40828828dda8982470023030a6c7d1cc

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