mcp-server-opencitations 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +112 -0
- package/package.json +39 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// OpenCitations MCP Server - Hello World Starter
|
|
4
|
+
// =============================================================================
|
|
5
|
+
// This is a minimal MCP server to help you learn TypeScript and MCP concepts.
|
|
6
|
+
// Comments explain TypeScript features as we go!
|
|
7
|
+
// -----------------------------------------------------------------------------
|
|
8
|
+
// IMPORTS
|
|
9
|
+
// -----------------------------------------------------------------------------
|
|
10
|
+
// In TypeScript, we import modules using ES6 syntax.
|
|
11
|
+
// The "from" path can be a package name or a relative file path.
|
|
12
|
+
// McpServer is the main class that handles MCP protocol communication
|
|
13
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
14
|
+
// StdioServerTransport handles communication over stdin/stdout
|
|
15
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
16
|
+
// 'z' is Zod - a TypeScript-first schema validation library
|
|
17
|
+
// It lets us define the shape of data and validate it at runtime
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
// -----------------------------------------------------------------------------
|
|
20
|
+
// SERVER SETUP
|
|
21
|
+
// -----------------------------------------------------------------------------
|
|
22
|
+
// Create a new MCP server instance.
|
|
23
|
+
// The object passed to McpServer is called an "object literal" in TypeScript.
|
|
24
|
+
// It has typed properties: 'name' and 'version' are both strings.
|
|
25
|
+
const server = new McpServer({
|
|
26
|
+
name: "opencitations-server", // Server identifier
|
|
27
|
+
version: "0.1.0", // Semantic versioning
|
|
28
|
+
});
|
|
29
|
+
// -----------------------------------------------------------------------------
|
|
30
|
+
// TOOL REGISTRATION
|
|
31
|
+
// -----------------------------------------------------------------------------
|
|
32
|
+
// MCP servers expose "tools" that LLMs can call.
|
|
33
|
+
// Let's register a simple "hello" tool.
|
|
34
|
+
// registerTool takes 3 arguments:
|
|
35
|
+
// 1. Tool name (string)
|
|
36
|
+
// 2. Tool configuration (object with description, inputSchema, etc.)
|
|
37
|
+
// 3. Handler function (async function that runs when tool is called)
|
|
38
|
+
server.registerTool("hello", // Tool name - this is what the LLM will use to call it
|
|
39
|
+
{
|
|
40
|
+
// Human-readable description - helps LLMs understand when to use this tool
|
|
41
|
+
description: "A simple hello world tool that greets the user",
|
|
42
|
+
// inputSchema defines what parameters this tool accepts
|
|
43
|
+
// We use Zod schemas here - they provide both TypeScript types AND runtime validation
|
|
44
|
+
inputSchema: {
|
|
45
|
+
// z.string() means this parameter must be a string
|
|
46
|
+
// .optional() means it's not required
|
|
47
|
+
// .describe() adds documentation for the LLM
|
|
48
|
+
name: z.string().optional().describe("Name to greet (optional)"),
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
// The handler function - this runs when the tool is called
|
|
52
|
+
// 'async' means this function can use 'await' for asynchronous operations
|
|
53
|
+
// The parameter 'args' is automatically typed based on our inputSchema!
|
|
54
|
+
async (args) => {
|
|
55
|
+
// TypeScript knows 'args.name' is string | undefined because of our schema
|
|
56
|
+
const greeting = args.name
|
|
57
|
+
? `Hello, ${args.name}! Welcome to OpenCitations MCP server.`
|
|
58
|
+
: "Hello! Welcome to OpenCitations MCP server.";
|
|
59
|
+
// Tools return a result object with a 'content' array
|
|
60
|
+
// Each content item has a 'type' (usually "text") and the actual content
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text", // 'as const' is a TypeScript assertion for literal types
|
|
65
|
+
text: greeting,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
// -----------------------------------------------------------------------------
|
|
71
|
+
// ANOTHER EXAMPLE: Tool with required parameters
|
|
72
|
+
// -----------------------------------------------------------------------------
|
|
73
|
+
server.registerTool("echo", {
|
|
74
|
+
description: "Echoes back the message you send (useful for testing)",
|
|
75
|
+
inputSchema: {
|
|
76
|
+
// No .optional() here - this parameter is required
|
|
77
|
+
message: z.string().describe("The message to echo back"),
|
|
78
|
+
},
|
|
79
|
+
}, async (args) => {
|
|
80
|
+
// TypeScript knows args.message is definitely a string (not undefined)
|
|
81
|
+
return {
|
|
82
|
+
content: [
|
|
83
|
+
{
|
|
84
|
+
type: "text",
|
|
85
|
+
text: `You said: "${args.message}"`,
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
// -----------------------------------------------------------------------------
|
|
91
|
+
// START THE SERVER
|
|
92
|
+
// -----------------------------------------------------------------------------
|
|
93
|
+
// This is an async function that starts our MCP server.
|
|
94
|
+
// In TypeScript, we use 'async function' for functions that return Promises.
|
|
95
|
+
async function main() {
|
|
96
|
+
// Promise<void> is the return type - void means we don't return a value
|
|
97
|
+
// The function is async, so it automatically returns a Promise
|
|
98
|
+
// Create a transport layer for stdin/stdout communication
|
|
99
|
+
const transport = new StdioServerTransport();
|
|
100
|
+
// Connect the server to the transport
|
|
101
|
+
// 'await' pauses execution until the Promise resolves
|
|
102
|
+
await server.connect(transport);
|
|
103
|
+
// Log to stderr (not stdout, which is used for MCP protocol messages)
|
|
104
|
+
console.error("OpenCitations MCP Server running on stdio");
|
|
105
|
+
}
|
|
106
|
+
// Run the main function and handle any errors
|
|
107
|
+
// .catch() handles any rejected promises (errors)
|
|
108
|
+
main().catch((error) => {
|
|
109
|
+
// 'unknown' is a safe type for caught errors in TypeScript
|
|
110
|
+
console.error("Fatal error:", error);
|
|
111
|
+
process.exit(1); // Exit with error code
|
|
112
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcp-server-opencitations",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for OpenCitations API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "ahmeshaf",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"mcp",
|
|
9
|
+
"model-context-protocol",
|
|
10
|
+
"opencitations",
|
|
11
|
+
"citations",
|
|
12
|
+
"api"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/ahmeshaf/mcp-server-opencitations"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"bin": {
|
|
20
|
+
"mcp-server-opencitations": "dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc && shx chmod +x dist/*.js",
|
|
27
|
+
"prepare": "npm run build",
|
|
28
|
+
"watch": "tsc --watch"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@modelcontextprotocol/sdk": "^1.24.0",
|
|
32
|
+
"zod": "^3.23.8"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/node": "^22",
|
|
36
|
+
"shx": "^0.3.4",
|
|
37
|
+
"typescript": "^5.8.2"
|
|
38
|
+
}
|
|
39
|
+
}
|