Code Semantic Service
Uses a local Ollama instance as the inference backend for code refactoring and semantic extraction. The server calls Ollama with a configurable host, model (default deepseek-coder), and timeout, and gracefully degrades to a rule-based engine when Ollama is unavailable.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Code Semantic Servicerefactor this Python snippet to useis Noneinstead of== None"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Code Semantic Service · 代码重构与语义提取
一个可自托管、也可直接调用的代码智能服务:代码重构 + 代码语义提取,同时提供 REST API、MCP Server、x402 付费接口三种接入方式。
核心逻辑不依赖任何前端框架,后端只有 FastAPI,推理走本地 Ollama,没有大模型时自动降级为规则引擎,保证服务永不 500。
在线试用
入口 | 地址 | 说明 |
交互页面 | 粘贴代码直接看重构结果 | |
MCP Server | Agent 可直接连接 | |
OpenAPI | https://ai-interview-coach-80785.app.workbuddy.host/openapi.public.json | 平台导入插件用 |
能力清单 | https://ai-interview-coach-80785.app.workbuddy.host/llms.txt | 给 Agent 读的纯文本说明 |
Related MCP server: FrameworkIA MCP Server
它解决什么问题
重构代码这件事,人做起来慢,用大模型直接做又不稳定:模型可能改掉业务逻辑、可能只给一段解释而不给完整代码、可能把缩进搞乱。
这个服务做了三件事来保证结果可用:
只输出代码,不夹带解释文字。提示词和输出清洗双管齐下,
refactor_code()返回的一定是可直接替换的代码。强制校验可运行性。Python 代码会过一遍
ast.parse,语法不合法就退回原代码并说明原因,绝不返回一段跑不起来的"重构结果"。没有模型也能干活。
fallback_refactor.py是纯规则引擎:== None→is None、清理未使用 import、统一缩进、补类型注解占位。机械改造语义等价,不会引入新 bug。
快速开始
方式一:MCP(推荐给 Agent)
任何支持 MCP 的客户端填这个地址即可,无需鉴权:
{
"mcpServers": {
"code-semantic": {
"type": "http",
"url": "https://ai-interview-coach-80785.app.workbuddy.host/mcp"
}
}
}提供的工具:
工具 | 作用 |
| 按任务重构代码,返回完整代码 |
| 提取函数/类/导入/调用的结构化摘要 |
| 按岗位 JD 生成面试题 |
| 5G NWDAF 网络分析查询 |
方式二:REST API
# 代码重构
curl -X POST https://ai-interview-coach-80785.app.workbuddy.host/api/code/refactor \
-H "Content-Type: application/json" \
-d '{"code":"def f(a):\n if a == None:\n return 0\n return a\n","language":"python"}'{
"result": "def f(a):\n if a is None:\n return 0\n return a\n",
"model": "deepseek-coder",
"language": "python",
"billable_units": 1,
"degraded": false,
"elapsed_ms": 842
}degraded=true 表示当前环境没有大模型、结果由规则引擎产出——服务不会假装模型可用。
方式三:x402 付费调用(Agent 原生付费)
不需要注册、不需要 API Key、不需要预充值。请求先拿到报价,再用钱包签名支付:
# 1) 首次请求会收到 402 + PAYMENT-REQUIRED 报价头
curl -i -X POST https://ai-interview-coach-80785.app.workbuddy.host/paid/refactor \
-H "Content-Type: application/json" -d '{"code":"x=1"}'
# 2) 带上 X-PAYMENT 头重试即可拿到结果
curl -X POST https://ai-interview-coach-80785.app.workbuddy.host/paid/refactor \
-H "Content-Type: application/json" \
-H "X-PAYMENT: <base64 支付载荷>" \
-d '{"code":"x=1"}'发现文件:/.well-known/x402
本地运行
python -m venv .venv && .venv/Scripts/activate # Windows
pip install -r requirements.txt
# 可选:接本地大模型(不接则走规则引擎)
ollama pull deepseek-coder
export OLLAMA_MODEL=deepseek-coder
python run.py # 默认 8000 端口,读 PORT 环境变量打开 http://127.0.0.1:8000/docs 看接口文档,或 http://127.0.0.1:8000/ 用交互页面。
环境变量
变量 | 默认 | 说明 |
| 8000 | 监听端口 |
| Ollama 地址 | |
| deepseek-coder | 模型名 |
| 120 | 推理超时(秒) |
| 1 | 模型不可用时是否降级到规则引擎 |
| 空 | 收款地址,留空则付费接口不接单 |
项目结构
core/
main.py FastAPI 入口(/refactor /semantic /health)
refactor.py 重构核心:提示词、Ollama 调用、输出清洗、AST 校验
code_semantic.py 语义提取:AST 优先,正则降级(支持多语言)
fallback_refactor.py 规则引擎:无模型时的等价改造
models.py Pydantic 请求/响应模型
adapters/ 各平台上架适配层(fal.ai / x402 / ClawMart / 扣子 / TapLaunch)
tests/ 接口级测试,19 项已知取巧与限制
不用 tree-sitter。非 Python 语言走正则降级,精度不如 AST,但零编译依赖,部署省心。要更高精度可自行接 tree-sitter。
降级模式不做语义理解。规则引擎只做机械等价的改造,重构质量远低于模型模式,所以响应里会明确标
degraded=true。x402 端点不做本地验签。签名验证交给链上/ facilitator,因为本地验签无法判断 nonce 是否已用,会漏掉重放攻击。
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP-Native LLM Orchestration Agent
- WauldoOAuthcom.wauldo
Stateless agentic tools over MCP: concept extraction, long-context, knowledge graph, planning.
Governed app access for AI agents: 1,000+ apps & 12,000+ tools via Code Mode MCP.
OCR, transcription, file extraction, and image generation for AI agents via MCP.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to search code by meaning, explore codebase structure, store and query knowledge with temporal facts, and read source code through a set of MCP tools.203 npm7MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI coding assistants to manage persistent memory, search project context, generate tests, review architecture, and orchestrate workflows through 15 MCP tools, enhancing context-aware code generation.-
- FlicenseNot gradedqualityBmaintenanceEnables AI agents to access unified development tools including code generation, documentation synchronization, test case rendering, and architecture graph queries through a single MCP server.-
- FlicenseNot gradedqualityAmaintenanceEnables AI assistants to save, retrieve, and semantically search code snippets, generate language-specific style guides, and produce comprehensive documentation through discoverable MCP tools and multi-agent workflows.-