crispparse-mcp 1.0.0 → 1.0.1
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/index.js +59 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -4,10 +4,19 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
4
4
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
5
5
|
|
|
6
6
|
const API_URL = process.env.CRISPPARSE_API_URL || "https://api.crispparse.com/v1/extract";
|
|
7
|
-
const
|
|
7
|
+
const DEFAULT_API_KEY = process.env.CRISPPARSE_API_KEY || "";
|
|
8
|
+
const DEFAULT_PAYMENT_SIGNATURE = process.env.CRISPPARSE_PAYMENT_SIGNATURE || "";
|
|
9
|
+
|
|
10
|
+
function safeJson(text) {
|
|
11
|
+
try {
|
|
12
|
+
return JSON.parse(text);
|
|
13
|
+
} catch {
|
|
14
|
+
return text;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
8
17
|
|
|
9
18
|
const server = new Server(
|
|
10
|
-
{ name: "crispparse-mcp-server", version: "1.0.
|
|
19
|
+
{ name: "crispparse-mcp-server", version: "1.0.1" },
|
|
11
20
|
{ capabilities: { tools: {} } }
|
|
12
21
|
);
|
|
13
22
|
|
|
@@ -15,12 +24,14 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
15
24
|
tools: [
|
|
16
25
|
{
|
|
17
26
|
name: "crispparse_extract",
|
|
18
|
-
description: "Extract clean, LLM-ready Markdown or structured JSON from any public URL using CrispParse.",
|
|
27
|
+
description: "Extract clean, LLM-ready Markdown or structured JSON from any public URL using CrispParse (supports Bearer Macaroon or x402 PAYMENT-SIGNATURE Base USDC proof).",
|
|
19
28
|
inputSchema: {
|
|
20
29
|
type: "object",
|
|
21
30
|
properties: {
|
|
22
31
|
url: { type: "string", description: "The full http:// or https:// URL to extract." },
|
|
23
|
-
mode: { type: "string", enum: ["markdown", "json"], description: "Output format (defaults to markdown)." }
|
|
32
|
+
mode: { type: "string", enum: ["markdown", "json"], description: "Output format (defaults to markdown)." },
|
|
33
|
+
api_key: { type: "string", description: "Optional CrispParse Macaroon bearer token (overrides CRISPPARSE_API_KEY)." },
|
|
34
|
+
payment_signature: { type: "string", description: "Optional x402 v2 PAYMENT-SIGNATURE Base USDC proof header (overrides CRISPPARSE_PAYMENT_SIGNATURE)." }
|
|
24
35
|
},
|
|
25
36
|
required: ["url"]
|
|
26
37
|
}
|
|
@@ -32,22 +43,64 @@ server.setRequestHandler(CallToolRequestSchema, async ({ params }) => {
|
|
|
32
43
|
if (params.name !== "crispparse_extract") {
|
|
33
44
|
return { isError: true, content: [{ type: "text", text: `Unknown tool: ${params.name}` }] };
|
|
34
45
|
}
|
|
46
|
+
|
|
35
47
|
const targetUrl = params.arguments?.url;
|
|
36
48
|
const mode = params.arguments?.mode === "json" ? "json" : "markdown";
|
|
49
|
+
const apiKey = (typeof params.arguments?.api_key === "string" && params.arguments.api_key) || DEFAULT_API_KEY;
|
|
50
|
+
const paymentSignature = (typeof params.arguments?.payment_signature === "string" && params.arguments.payment_signature) || DEFAULT_PAYMENT_SIGNATURE;
|
|
51
|
+
|
|
37
52
|
if (!targetUrl || typeof targetUrl !== "string") {
|
|
38
53
|
return { isError: true, content: [{ type: "text", text: "Missing required parameter: url" }] };
|
|
39
54
|
}
|
|
55
|
+
|
|
40
56
|
try {
|
|
41
57
|
const headers = {
|
|
42
58
|
"Content-Type": "application/json",
|
|
43
|
-
...(
|
|
59
|
+
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
60
|
+
...(paymentSignature ? { "PAYMENT-SIGNATURE": paymentSignature } : {})
|
|
44
61
|
};
|
|
62
|
+
|
|
45
63
|
const response = await fetch(API_URL, {
|
|
46
64
|
method: "POST",
|
|
47
65
|
headers,
|
|
48
66
|
body: JSON.stringify({ url: targetUrl, mode })
|
|
49
67
|
});
|
|
50
|
-
|
|
68
|
+
|
|
69
|
+
const bodyText = await response.text();
|
|
70
|
+
|
|
71
|
+
if (response.status === 402) {
|
|
72
|
+
return {
|
|
73
|
+
isError: true,
|
|
74
|
+
content: [
|
|
75
|
+
{
|
|
76
|
+
type: "text",
|
|
77
|
+
text: JSON.stringify({
|
|
78
|
+
status: 402,
|
|
79
|
+
paymentRequired: response.headers.get("payment-required"),
|
|
80
|
+
body: safeJson(bodyText)
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const paymentResponse = response.headers.get("payment-response");
|
|
88
|
+
if (response.ok && paymentResponse) {
|
|
89
|
+
return {
|
|
90
|
+
isError: false,
|
|
91
|
+
content: [
|
|
92
|
+
{
|
|
93
|
+
type: "text",
|
|
94
|
+
text: JSON.stringify({
|
|
95
|
+
paymentResponse,
|
|
96
|
+
result: safeJson(bodyText)
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
]
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return { isError: !response.ok, content: [{ type: "text", text: bodyText }] };
|
|
51
104
|
} catch (error) {
|
|
52
105
|
return {
|
|
53
106
|
isError: true,
|
package/package.json
CHANGED