FastMcp 案例一(Stdio)

参考链接:【AI入门】CherryStudio入门3:结合FastMCP创建自己的MCP服务,实现哔哩视频查询_fastmcp cherry studio-CSDN博客

1、首先安装python环境

conda create -n mcp python=3.10

2、安装依赖

pip install fastmcp

3、编写一个server.py

# -*- coding: utf-8 -*-
# @Time : 2025/7/28 15:21
# @Author : yangwenjie
# @Email : 邮箱
# @File : server.py
# @Project : fastmcp

from fastmcp import FastMCP
mcp = FastMCP(name="First Mcp")


@mcp.tool
def add(a: int, b: int) -> int:
    """
    Adds two integer numbers togather
    :param a:
    :param b:
    :return:
    """
    return  a + b

@mcp.resource("resource://config")
def get_config() -> dict:
    """Provides the application's configuration"""
    return {"version": "1.0", "author": "Myteam"}


if __name__ == "__main__":
    mcp.run()

4、debug测试

fastmcp dev server.py
Need to install the following packages:
@modelcontextprotocol/inspector@0.16.2
Ok to proceed? (y) y
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@modelcontextprotocol/inspector@0.16.2',
npm WARN EBADENGINE   required: { node: '>=22.7.5' },
npm WARN EBADENGINE   current: { node: 'v18.20.2', npm: '10.5.0' }
npm WARN EBADENGINE }
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: 'eventsource-parser@3.0.3',
npm WARN EBADENGINE   required: { node: '>=20.0.0' },
npm WARN EBADENGINE   current: { node: 'v18.20.2', npm: '10.5.0' }
npm WARN EBADENGINE }
Starting MCP inspector...
⚙️ Proxy server listening on localhost:6277
🔑 Session token: 9f7b5862af6f9762998693d0176fd4464c26a8a3520895a8951cab200d416f62
   Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth

🚀 MCP Inspector is up and running at:
   http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=9f7b5862af6f9762998693d0176fd4464c26a8a3520895a8951cab200d416f62

🌐 Opening browser...
New STDIO connection request

5、打开浏览器

image

 

posted @ 2025-07-28 17:06  小白啊小白,Fighting  阅读(173)  评论(0)    收藏  举报