Skip to content

Commit d2e0029

Browse files
committed
updated the versions and fixed the swagger now you can access the endpoints with http://localhost:7860/swagger-ui/index.html
1 parent 921f3ad commit d2e0029

File tree

7 files changed

+140
-3
lines changed

7 files changed

+140
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ build/
3535
.vscode/
3636

3737
### Mac OS ###
38-
.DS_Store
38+
.DS_Store
39+
/src/main/resources/node_modules/

mcp/chat1.png

60.9 KB
Loading

mcp/tools1.png

55.4 KB
Loading

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
<dependency>
4242
<groupId>io.github.vishalmysore</groupId>
4343
<artifactId>a2ajava</artifactId>
44-
<version>0.0.7.8</version>
44+
<version>0.0.7.10</version>
4545
</dependency>
4646

4747

src/main/java/io/github/vishalmysore/MCPController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
@RequestMapping("/mcp")
2020
public class MCPController extends MCPToolsController {
2121

22-
22+
@GetMapping("/server-config")
23+
public ResponseEntity<Map<String, String>> getServerConfig() {
24+
return super.getServerConfig();
25+
}
2326

2427
SseEmitter lastEmitter;
2528
// @GetMapping("/sse")

src/main/resources/mcpserver.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3+
import { CallToolRequestSchema, ListResourcesRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
4+
import fs from 'node:fs/promises';
5+
6+
const logFilePath = '/temp/proxy_server.log';
7+
8+
const SERVER_BASE_URL = process.env.SERVER_BASE_URL || "http://localhost:7860";
9+
10+
// Create server
11+
const server = new Server({
12+
name: "springboot-proxy",
13+
version: "1.0.0",
14+
}, {
15+
capabilities: {
16+
tools: {}, // We'll load tools dynamically from Spring Boot
17+
},
18+
});
19+
20+
// Handler: List tools from Spring Boot
21+
server.setRequestHandler(ListToolsRequestSchema, async () => {
22+
try {
23+
const response = await fetch("http://localhost:7860/mcp/list-tools", {
24+
method: "GET",
25+
headers: { "Content-Type": "application/json" }
26+
});
27+
28+
if (!response.ok) {
29+
const errorMessage = `Failed to fetch tools: ${response.statusText}`;
30+
// await logToFile(errorMessage);
31+
throw new Error(errorMessage);
32+
}
33+
34+
const data = await response.json();
35+
// await logToFile(`Available tools from Spring Boot: ${JSON.stringify(data, null, 2)}`);
36+
return {
37+
tools: data.tools,
38+
};
39+
} catch (error) {
40+
console.error("Error listing tools:", error);
41+
throw error;
42+
}
43+
});
44+
// Handler: Call a tool by proxying to Spring Boot
45+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
46+
try {
47+
fs.appendFile(logFilePath, "receivedResponseLog", 'utf8');
48+
// 🔍 Log the outgoing request
49+
const outgoingRequestLog = "➡️ Sending request to Spring Boot:\n" + JSON.stringify({
50+
name: request.params.name,
51+
arguments: request.params.arguments ?? {},
52+
}, null, 2);
53+
// await logToFile(outgoingRequestLog);
54+
55+
const response = await fetch("http://localhost:7860/mcp/call-tool", {
56+
method: "POST",
57+
headers: { "Content-Type": "application/json" },
58+
body: JSON.stringify({
59+
name: request.params.name,
60+
arguments: request.params.arguments ?? {},
61+
}),
62+
});
63+
64+
// ❌ Log failure if not OK
65+
if (!response.ok) {
66+
const errorText = await response.text(); // Read error body
67+
const errorMessage = `❌ Tool call failed: ${response.statusText}\n🔻 Error response body: ${errorText}`;
68+
await logToFile(errorMessage);
69+
throw new Error(`Tool call failed: ${response.statusText}`);
70+
}
71+
72+
// console.log(response.json());
73+
// ✅ Log the response data
74+
const data = await response.json();
75+
fs.appendFile(logFilePath, "-----------------------------", 'utf8');
76+
fs.appendFile(logFilePath, JSON.stringify(data["result"]), 'utf8');
77+
fs.appendFile(logFilePath, "-----------------------------", 'utf8');
78+
79+
// Log the received response
80+
// console.log("------------------------------------------");
81+
// console.log("Received response from Spring Boot:", data);
82+
// console.log("------------------------------------------");
83+
// const receivedResponseLog = "✅ Received response from Spring Boot:\n" + JSON.stringify(data, null, 2);
84+
// fs.appendFile(logFilePath, receivedResponseLog, 'utf8');
85+
// let res = {"content":[{"annotations":null,"text":"Temprature for toronto is 18.0","type":"text"}],"isError":false,"_meta":null};
86+
// json remove attribute _meta
87+
88+
const res = data.result;
89+
delete res._meta;
90+
delete res.isError;
91+
// console.log("Received response from Spring Boot:", res);
92+
return res; // Must match CallToolResponseSchema
93+
} catch (error) {
94+
console.error("Error calling tool:", error);
95+
throw error;
96+
}
97+
});
98+
99+
100+
101+
// Launch server over stdio
102+
async function runServer() {
103+
const transport = new StdioServerTransport();
104+
await server.connect(transport);
105+
// await logToFile("Proxy server is running on stdio...");
106+
}
107+
108+
runServer().catch(console.error);

src/main/resources/package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "mcp-sqlagent-server",
3+
"version": "0.1.1",
4+
"description": "MCP server for interacting with SQL databases.",
5+
"license": "MIT",
6+
"author": "Vishal Mysore",
7+
"homepage": "https://github.com/vishalmysore/SqlAIAgent",
8+
"bugs": "https://github.com/vishalmysore/SqlAIAgent",
9+
"type": "module",
10+
"bin": {
11+
"mcp-server-browserbase": "mcpserver.js"
12+
},
13+
"files": [
14+
"dist"
15+
],
16+
17+
"dependencies": {
18+
"@modelcontextprotocol/sdk": "^1.0.3",
19+
"puppeteer-core": "^23.9.0"
20+
},
21+
"devDependencies": {
22+
"shx": "^0.3.4",
23+
"typescript": "^5.6.2"
24+
}
25+
}

0 commit comments

Comments
 (0)