-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp-server.js
More file actions
76 lines (69 loc) · 2.23 KB
/
mcp-server.js
File metadata and controls
76 lines (69 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env node
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
const fetch = require('node-fetch');
const server = new Server({
name: 'pdf-form-engine',
version: '1.0.0',
}, {
capabilities: {
tools: {}
}
});
// Tool to extract PDF fields
server.setRequestHandler('tools/call', async (request) => {
const { name, arguments: args } = request.params;
switch (name) {
case 'extract_pdf_fields':
const extractResponse = await fetch('http://localhost:3001/api/fill-url', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ file_url: args.file_url, fields: {} })
});
const extractData = await extractResponse.json();
return { toolResult: extractData };
case 'fill_pdf':
const fillResponse = await fetch('http://localhost:3001/api/fill-url', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ file_url: args.file_url, fields: args.fields })
});
const fillData = await fillResponse.json();
return { toolResult: fillData };
default:
throw new Error(`Unknown tool: ${name}`);
}
});
// Tool definitions
server.setRequestHandler('tools/list', async () => {
return {
tools: [
{
name: 'extract_pdf_fields',
description: 'Extract form fields from a PDF file',
inputSchema: {
type: 'object',
properties: {
file_url: { type: 'string', description: 'URL of the PDF file' }
},
required: ['file_url']
}
},
{
name: 'fill_pdf',
description: 'Fill a PDF form with provided field values',
inputSchema: {
type: 'object',
properties: {
file_url: { type: 'string', description: 'URL of the PDF file' },
fields: { type: 'object', description: 'Field values to fill' }
},
required: ['file_url', 'fields']
}
}
]
};
});
const transport = new StdioServerTransport();
server.connect(transport);
console.error('PDF Form Engine MCP Server running...');