feat(gencode): 优化代码生成器功能并修复类型映射问题

refactor(discover): 重构路由发现模块,增强错误处理和日志记录

fix(constant): 修正TINYINT类型映射为Boolean

style(vue): 调整前端模板格式和样式

chore: 清理无用文件和更新依赖项

perf(jinja2): 改进模板工具性能和类型处理

docs: 更新注释和文档字符串

test: 移除过时的测试文件
This commit is contained in:
zhangtao
2026-01-05 01:11:35 +08:00
parent c178b996a4
commit c40ed5b599
17 changed files with 554 additions and 499 deletions
@@ -1,111 +0,0 @@
""" 图像输入 """
# From URL
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this image."},
{"type": "image", "url": "https://example.com/path/to/image.jpg"},
]
}
# From base64 data
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this image."},
{
"type": "image",
"base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
"mime_type": "image/jpeg",
},
]
}
# From provider-managed File ID
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this image."},
{"type": "image", "file_id": "file-abc123"},
]
}
""" PDF文档输入 """
# From URL
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this document."},
{"type": "file", "url": "https://example.com/path/to/document.pdf"},
]
}
# From base64 data
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this document."},
{
"type": "file",
"base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
"mime_type": "application/pdf",
},
]
}
# From provider-managed File ID
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this document."},
{"type": "file", "file_id": "file-abc123"},
]
}
""" 音频输入 """
# From base64 data
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this audio."},
{
"type": "audio",
"base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
"mime_type": "audio/wav",
},
]
}
# From provider-managed File ID
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this audio."},
{"type": "audio", "file_id": "file-abc123"},
]
}
""" 视频输入 """
# From base64 data
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this video."},
{
"type": "video",
"base64": "AAAAIGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb2...",
"mime_type": "video/mp4",
},
]
}
# From provider-managed File ID
message = {
"role": "user",
"content": [
{"type": "text", "text": "Describe the content of this video."},
{"type": "video", "file_id": "file-abc123"},
]
}
@@ -1,65 +0,0 @@
import asyncio
from fastmcp import Client
from fastmcp import FastMCP
import asyncio
# 转换为 MCP 服务器
mcp = FastMCP.from_fastapi(app=app)
async def demo():
async with Client(mcp) as client:
# 列出可用工具
tools = await client.list_tools()
for tool in tools:
print(f"工具: {tool.name}")
print(f"描述: {tool.description}")
if tool.inputSchema:
print(f"参数: {tool.inputSchema}")
# 访问标签和其他元数据
if hasattr(tool, 'meta') and tool.meta:
fastmcp_meta = tool.meta.get('_fastmcp', {})
print(f"标签: {fastmcp_meta.get('tags', [])}")
resources = await client.list_resources()
for resource in resources:
print(f"资源 URI: {resource.uri}")
print(f"名称: {resource.name}")
print(f"描述: {resource.description}")
print(f"MIME 类型: {resource.mimeType}")
# 访问标签和其他元数据
if hasattr(resource, '_meta') and resource._meta:
fastmcp_meta = resource._meta.get('_fastmcp', {})
print(f"标签: {fastmcp_meta.get('tags', [])}")
prompts = await client.list_prompts()
for prompt in prompts:
print(f"提示: {prompt.name}")
print(f"描述: {prompt.description}")
if prompt.arguments:
print(f"参数: {[arg.name for arg in prompt.arguments]}")
# 访问标签和其他元数据
if hasattr(prompt, '_meta') and prompt._meta:
fastmcp_meta = prompt._meta.get('_fastmcp', {})
print(f"标签: {fastmcp_meta.get('tags', [])}")
# 创建产品
result = await client.call_tool(
"create_product_products_post",
{
"name": "无线键盘",
"price": 79.99,
"category": "电子产品",
"description": "蓝牙机械键盘"
}
)
print(f"已创建产品: {result.data}")
# 列出价格低于 $100 的电子产品
result = await client.call_tool(
"list_products_products_get",
{"category": "电子产品", "max_price": 100}
)
print(f"经济实惠的电子产品: {result.data}")
if __name__ == "__main__":
asyncio.run(demo())
@@ -1,49 +0,0 @@
from fastmcp import FastMCP
from fastmcp.prompts.prompt import Message
from mcp.types import PromptMessage, TextContent
app = FastMCP("Math")
mcp = FastMCP.from_fastapi(app=app)
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
@mcp.tool()
def multiply(a: int, b: int) -> int:
"""Multiply two numbers"""
return a * b
# 返回字符串的基本动态资源
@mcp.resource("resource://greeting")
def get_greeting() -> str:
"""提供简单的问候消息。"""
return "Hello from FastMCP Resources!"
# 返回 JSON 数据的资源(字典会自动序列化)
@mcp.resource("data://config")
def get_config() -> dict:
"""以 JSON 形式提供应用程序配置。"""
return {
"theme": "dark",
"version": "1.2.0",
"features": ["tools", "resources"],
}
# 返回字符串的基本提示(自动转换为用户消息)
@mcp.prompt
def ask_about_topic(topic: str) -> str:
"""生成询问主题解释的用户消息。"""
return f"Can you please explain the concept of '{topic}'?"
# 返回特定消息类型的提示
@mcp.prompt
def generate_code_request(language: str, task_description: str) -> PromptMessage:
"""生成请求代码生成的用户消息。"""
content = f"Write a {language} function that performs the following task: {task_description}"
return PromptMessage(role="user", content=TextContent(type="text", text=content))
if __name__ == "__main__":
mcp.run(transport="stdio")
# fastmcp run my_server.py:mcp --transport http --port 8000