Skip to content

Commit 56ebc63

Browse files
committed
feat: initial commit
Signed-off-by: frank-zsy <[email protected]>
0 parents  commit 56ebc63

8 files changed

+695
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode
2+
.idea
3+
.DS_Store
4+
*.swp
5+
*.lock
6+
7+
*/**/node_modules
8+
lib
9+
dist
10+
node_modules

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# OpenDigger MCP Server
2+
3+
This is a simple OpenDigger MCP server to get LLMs access to OpenDigger data by MCP tools.
4+
5+
With this server installed, you can interact with it in LLMs to get online data of OpenDigger and get insights of the data.

index.ts

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/usr/bin/env node
2+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4+
import {
5+
CallToolRequestSchema,
6+
ListToolsRequestSchema,
7+
} from "@modelcontextprotocol/sdk/types.js";
8+
import { z } from 'zod';
9+
import { zodToJsonSchema } from 'zod-to-json-schema';
10+
11+
import { fetchData } from './utils.js';
12+
import { VERSION } from './version.js';
13+
14+
const server = new Server(
15+
{
16+
name: "open-digger-mcp-server",
17+
version: VERSION,
18+
},
19+
{
20+
capabilities: {
21+
tools: {},
22+
},
23+
}
24+
);
25+
26+
const BASE_URL = 'https://oss.open-digger.cn/';
27+
28+
const inputSchema = z.object({
29+
platform: z.enum(['GitHub', 'Gitee']).describe('Platform of the repo or user (GitHub, Gitee).'),
30+
entityType: z.enum(['Repo', 'User']).describe('What is the entity of the metric (Repo, User).'),
31+
owner: z.string().optional().describe('The owner name of the repo to get a metric data.'),
32+
repo: z.string().optional().describe('The repo name of the repo to get a metric data.'),
33+
login: z.string().optional().describe('The user login to get a metric data of a user.'),
34+
metricName: z.enum(['openrank', 'community_openrank', 'activity']).describe('The metric name to get the data.'),
35+
});
36+
37+
server.setRequestHandler(ListToolsRequestSchema, async () => {
38+
return {
39+
tools: [
40+
{
41+
name: "get_open_digger_metric",
42+
description: "Get metric data of OpenDigger",
43+
inputSchema: zodToJsonSchema(inputSchema),
44+
},
45+
],
46+
};
47+
});
48+
49+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
50+
try {
51+
if (!request.params.arguments) {
52+
throw new Error("Arguments are required");
53+
}
54+
55+
switch (request.params.name) {
56+
case 'get_open_digger_metric': {
57+
const args = inputSchema.parse(request.params.arguments);
58+
const platform = args.platform.toString().toLowerCase();
59+
let url = '';
60+
if (args.entityType === 'Repo') {
61+
url = `${BASE_URL}${platform}/${args.owner}/${args.repo}/${args.metricName}.json`;
62+
} else {
63+
url = `${BASE_URL}${platform}/${args.login}/${args.metricName}.json`;
64+
}
65+
66+
const data = await fetchData(url);
67+
return {
68+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
69+
};
70+
}
71+
72+
default:
73+
throw new Error(`Unknown tool: ${request.params.name}`);
74+
}
75+
} catch (e) {
76+
if (e instanceof z.ZodError) {
77+
throw new Error(`Invalid input: ${JSON.stringify(e.errors)}`);
78+
}
79+
throw e;
80+
}
81+
});
82+
83+
async function main() {
84+
const transport = new StdioServerTransport();
85+
await server.connect(transport);
86+
console.error("OpenDigger MCP Server running on stdio");
87+
}
88+
89+
main().catch((error) => {
90+
console.error("Fatal error in main():", error);
91+
process.exit(1);
92+
});

0 commit comments

Comments
 (0)