基于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.6.tar.gz
(4.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_adapter-0.0.6.tar.gz.
File metadata
- Download URL: mcp_adapter-0.0.6.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7271113380cb9003e5cf8ab18dd92127ffeb5c63b2dc991f64b9b33ed7788432
|
|
| MD5 |
5fccae262f35c37479d497270e28f316
|
|
| BLAKE2b-256 |
c9de1ea0dea6a66c2de59cc2c419c875c643a384f8500481e4636ae49e0715b3
|
File details
Details for the file mcp_adapter-0.0.6-py3-none-any.whl.
File metadata
- Download URL: mcp_adapter-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a4e20d0c661ac6292b04ec32be9ec8a984160a4c01196ce21b89b6db29f65e4
|
|
| MD5 |
96c5c89e37ca0073bb1a2d606449644a
|
|
| BLAKE2b-256 |
489dde92ebfdd7d8366830d6fdd32972e622ca53c809aba16891a84d9c294114
|