惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
Cloudbric
Cloudbric
The Register - Security
The Register - Security
小众软件
小众软件
PCI Perspectives
PCI Perspectives
G
Google Developers Blog
AI
AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
Recent Commits to openclaw:main
Recent Commits to openclaw:main
量子位
TaoSecurity Blog
TaoSecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
F
Full Disclosure
N
Netflix TechBlog - Medium
博客园_首页
Last Week in AI
Last Week in AI
A
Arctic Wolf
B
Blog RSS Feed
J
Java Code Geeks
C
Cybersecurity and Infrastructure Security Agency CISA
I
InfoQ
aimingoo的专栏
aimingoo的专栏
云风的 BLOG
云风的 BLOG
NISL@THU
NISL@THU
MyScale Blog
MyScale Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Jina AI
Jina AI
有赞技术团队
有赞技术团队
S
Schneier on Security
L
Lohrmann on Cybersecurity
P
Privacy & Cybersecurity Law Blog
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Security Latest
Security Latest
Vercel News
Vercel News
博客园 - 司徒正美
Webroot Blog
Webroot Blog
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans

Yunfeng's Simple Blog

2025年终总结 lyrichroma-一键将语音转换为视频的Python命令行工具 JiT论文阅读Back to Basics-Let Denoising Generative Models Denoise Lepton AI后续 llm-code-scorer wavlm-large模型onnx和mnn版本的导出与使用 解决Manus Blog自动跳转无法访问的问题 Pytorch转ONNX报错-Cannot insert a Tensor that requires grad as a constant 用MOSS-TTSD生成相声 张小珺明超平访谈观点总结 Qwen VLo 效果实测 美团 NoCode 简单使用体验 AI时代的产品文本化 Comma v0.1 -全开源数据训练的可复现大模型 repetition_penality的作用与实现 git lfs pointer 报错解决 bitnet-b1.58-2b-4t Neovim conceal机制导致markdown语法隐藏的问题 Quotation Armin Ronacher's Reflecting on Life
用gradio部署mcp server
Yunfeng Wang · 2025-06-04 · via Yunfeng's Simple Blog

1. 说明

mcp是一种创新的开源协议,用于规范大模型对外部工具的调用流程。mcp服务是供大模型调用的外部服务,用于增强大模型解决问题的能力。

mcp服务可以用mcp python-sdk来搭建,官方教程在这里。对第一次尝试的同学来说,官方的sdk还是有一定门槛的。

最近发现gradio 默认支持mcp server的部署,也就是launch一个gradio demo后,默认就起一个mcp服务,无需额外学习mcp python sdk的使用。这对于已经熟悉gradio demo搭建的同学来说,方便了不少。下面我将展示一个简单的基于gradio的mcp server搭建,以及在一个mcp client中调用。

2. mcp server搭建

首先需要安装graidio[mcp],一行命令搞定:pip install -U "gradio[mcp]"

使用时,在demo.launch函数调用中增加一个参数 mcp_server=True 即可,下面是一个最简单例子:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import gradio as gr

def sum_two_values(a, b):
"""
Sum value a and b

Args:
a (str): The first value
b (str): The second value

Returns:
int: result of a + b
"""
return int(a) + int(b)

demo = gr.Interface(
fn=sum_two_values,
inputs=[gr.Textbox(1024), gr.Textbox(512)],
outputs=[gr.Number()],
title="Sum Two Values",
description="Input two values and I will return the sum of them",
)

if __name__ == "__main__":
demo.launch(mcp_server=True)

我们写了一个把两个数相加的函数sum_two_values,通过详细的docstring对函数功能、输入参数、输出参数的类型、含义进行说明,这有助于大模型来正确地调用工具。

然后创建了一个gradio的Interface界面,设计输入输出,调用上面的函数。

最后启动interface界面,设置mcp_server=True

执行这个脚本后,log输出如下:

1
2
3
4
 Running on local URL:  http://127.0.0.1:7860
* To create a public link, set `share=True` in `launch()`.

🔨 MCP server (using SSE) running at: http://127.0.0.1:7860/gradio_api/mcp/sse

首先是跟普通的gradio demo一样,列出网页服务的ip和端口。

然后列出了mcp server的地址,这个地址就可以加到mcp client 里面,进行mcp server的调用(具体见下章节)。

我们打开网页服务的网址,网页底下有通过 API 或 MCP 使用 按钮,点击之后选择MCP tab,也会给出MCP的地址:

3. mcp client中调用服务

mcp client有很多选择,cursor, cline, trae,通义灵码等。这里以通义灵码 IDE为例,展示添加mcp server 地址并调用的流程,别的工具几乎也是一样的使用流程。

打开IDE,选择智能体模式,点击智能会话底部的MCP工具链接,进入配置:

配置文件如下:

1
2
3
4
5
6
7
{
"mcpServers": {
"gradio": {
"url": "http://127.0.0.1:7860/gradio_api/mcp/sse"
}
}
}

服务添加好以后,就可以在聊天的时候进行使用了:

mcp server的功能五花八门,通过这些工具,能对大模型的能力进行补充,完成更复杂的任务。