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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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
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的功能五花八门,通过这些工具,能对大模型的能力进行补充,完成更复杂的任务。