
openapi mcp server
把使用openapi作为接口文档的用springboot构建的web应用转成mcp server
Repository Info
About This Server
把使用openapi作为接口文档的用springboot构建的web应用转成mcp server
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
概述
能直接让使用openapi(swagger)作为接口文档的接口支持mcp,应用成为一个mcp server。
- 多Session支持
- 认证支持
价值在于有mcp client(如cursor,claude desktop等)就能完成业务操作,而不用写前端页面(Claude Sonnet 3.7实测无敌) 另外未来一定有基于AI的超级app出现。在基于语言的新的交互方式下,我们只需要写后端接口就行了
要求
- Java 17+
- SpringBoot
- SpringMVC
快速开始
- 加入依赖,mcp原生依赖
<dependency>
<groupId>io.modelcontextprotocol.sdk</groupId>
<artifactId>mcp-spring-webmvc</artifactId>
<version>0.7.0</version>
</dependency>
-
复制代码
InternalWebMvcSseServerTransport.javaMcpConfig.javaRestApiToolProvider.javaUserContextSetter.java -
实现
UserContextSetter接口 Demo
@Component
@AllArgsConstructor
public class MyUserContextSetter implements UserContextSetter{
private JwtConfig jwtConfig;
@Override
public void set(String auth) {
UserContext.set(jwtConfig.getUserContextFromTokenWithoutException(auth));
}
@Override
public void clear() {
UserContext.clear();
}
}
-
补充其他基础设施(拦截器等)以满足业务需求
-
客户端Demo
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
const transport = new SSEClientTransport(new URL("http://localhost:8080/mcp/sse/eyJhbGciOiJIUzI1NiJ9.eyJ0ZW5hbnRfaWQiOjIsImlzX2FkbWluIjpmYWxzZSwic3ViIjoiMiIsImlhdCI6MTc0MzA4MTE5MiwiZXhwIjoxNzQzMTY3NTkyfQ.newz2wj0l5nWk1U_lHNg575bi1FubWSLXqji4o2W-P0"));
const client = new Client(
{
name: "MCP Server",
version: "1.0.0"
}
);
await client.connect(transport);
const tools = await client.listTools();
// List all tools
console.log("Tools: ", JSON.stringify(tools));
// Call a tool
const result = await client.callTool({
name: "TenantController.pageUser",
arguments: {
current: 1,
pageSize: 10
}
});
console.log("Result: ", JSON.stringify(result));
Quick Start
Clone the repository
git clone https://github.com/h2562961224/openapi-mcp-serverInstall dependencies
cd openapi-mcp-server
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.