Skip to content

Commit 6496f2a

Browse files
committedMar 20, 2025
feat: add more metrics and prompt
Signed-off-by: frank-zsy <[email protected]>
1 parent 56ebc63 commit 6496f2a

File tree

1 file changed

+71
-16
lines changed

1 file changed

+71
-16
lines changed
 

‎index.ts

+71-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env node
2-
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
3+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
44
import {
55
CallToolRequestSchema,
6+
GetPromptRequestSchema,
7+
ListPromptsRequestSchema,
68
ListToolsRequestSchema,
7-
} from "@modelcontextprotocol/sdk/types.js";
9+
} from '@modelcontextprotocol/sdk/types.js';
810
import { z } from 'zod';
911
import { zodToJsonSchema } from 'zod-to-json-schema';
1012

@@ -13,12 +15,13 @@ import { VERSION } from './version.js';
1315

1416
const server = new Server(
1517
{
16-
name: "open-digger-mcp-server",
18+
name: 'open-digger-mcp-server',
1719
version: VERSION,
1820
},
1921
{
2022
capabilities: {
2123
tools: {},
24+
prompts: {},
2225
},
2326
}
2427
);
@@ -31,20 +34,26 @@ const inputSchema = z.object({
3134
owner: z.string().optional().describe('The owner name of the repo to get a metric data.'),
3235
repo: z.string().optional().describe('The repo name of the repo to get a metric data.'),
3336
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.'),
37+
metricName: z.enum([
38+
'openrank',
39+
'stars',
40+
'participants',
41+
'contributors',
42+
'issues_new',
43+
'change_requests',
44+
'issue_comments',
45+
]).describe('The metric name to get the data.'),
3546
});
3647

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+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
49+
tools: [
50+
{
51+
name: 'get_open_digger_metric',
52+
description: 'Get metric data of OpenDigger',
53+
inputSchema: zodToJsonSchema(inputSchema),
54+
},
55+
],
56+
}));
4857

4958
server.setRequestHandler(CallToolRequestSchema, async (request) => {
5059
try {
@@ -80,6 +89,52 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
8089
}
8190
});
8291

92+
server.setRequestHandler(ListPromptsRequestSchema, async () => ({
93+
prompts: Object.values({
94+
name: 'open_source_repo_analysis',
95+
description: 'Comprehensive analysis of open source repo with OpenDigger data',
96+
arguments: [
97+
{ name: 'platform', description: 'The platform of the repo to analysis', required: true },
98+
{ name: 'owner', description: 'The owner of the repo to analysis', required: true },
99+
{ name: 'repo', description: 'The name of the repo to analysis', required: true }
100+
]
101+
}),
102+
}));
103+
104+
server.setRequestHandler(GetPromptRequestSchema, async (request) => {
105+
if (request.params.name === 'open_source_repo_analysis') {
106+
const platform = request.params.arguments?.platform;
107+
const owner = request.params.arguments?.owner;
108+
const repo = request.params.arguments?.repo;
109+
110+
return {
111+
messages: [
112+
{
113+
role: 'user',
114+
content: {
115+
type: 'text',
116+
text: `
117+
Generate a comprehensive report of ${owner}/${repo} repo on ${platform}, the OpenRank, stars, participants and contributors metrics are most important to give a report of the repo.
118+
119+
Notice that:
120+
121+
- OpenRank metric shows a general influence level of the repo, more influential developers with more activities in the repo leads to higher OpenRank value.
122+
- Participants metric means developers count that has issues or pull requests activity like open new issue or PR, any issue comment or PR review in the repo.
123+
- Contributors metrics means how many developers has merged PR in the repo for given period.
124+
- Stars metric shows the popular level of the repo, which is how many developers give a star to the repo.
125+
- If the repo was created more than 3 year ago, use yearly data; If the repo was created more than 1 year ago, use quarterly data; Else, use monthly data.
126+
127+
Generate the report in HTML format that can be directly open by browser and has quite beatiful visulization, make sure that give comprehensive insights for each metric above along with the visulization charts like how's the data trending in the time period.
128+
`
129+
}
130+
}
131+
]
132+
};
133+
}
134+
135+
throw new Error("Prompt implementation not found");
136+
});
137+
83138
async function main() {
84139
const transport = new StdioServerTransport();
85140
await server.connect(transport);

0 commit comments

Comments
 (0)
Please sign in to comment.