@agents-txt/mcp 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/LICENSE +21 -0
- package/dist/chunk-RNL5YPEA.js +81 -0
- package/dist/chunk-TLN4YSVV.js +130 -0
- package/dist/cli.cjs +153 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +26 -0
- package/dist/index.cjs +156 -0
- package/dist/index.d.cts +19 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +6 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 agents-txt contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { AgentsTxtClient } from "@agents-txt/core";
|
|
4
|
+
async function createAgentsTxtServer(targetUrl) {
|
|
5
|
+
const client = new AgentsTxtClient();
|
|
6
|
+
let result = await client.discoverJSON(targetUrl);
|
|
7
|
+
if (!result.success) {
|
|
8
|
+
result = await client.discover(targetUrl);
|
|
9
|
+
}
|
|
10
|
+
if (!result.success || !result.document) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Failed to discover agents.txt at ${targetUrl}: ${result.errors.map((e) => e.message).join(", ")}`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
const doc = result.document;
|
|
16
|
+
const server = new McpServer({
|
|
17
|
+
name: `agents-txt: ${doc.site.name}`,
|
|
18
|
+
version: "0.1.0"
|
|
19
|
+
});
|
|
20
|
+
for (const cap of doc.capabilities) {
|
|
21
|
+
if (cap.protocol === "REST") {
|
|
22
|
+
registerRestTool(server, cap);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { server, document: doc };
|
|
26
|
+
}
|
|
27
|
+
function registerRestTool(server, cap) {
|
|
28
|
+
const properties = {};
|
|
29
|
+
const required = [];
|
|
30
|
+
if (cap.parameters) {
|
|
31
|
+
for (const param of cap.parameters) {
|
|
32
|
+
properties[param.name] = {
|
|
33
|
+
type: param.type === "integer" ? "number" : param.type,
|
|
34
|
+
description: param.description
|
|
35
|
+
};
|
|
36
|
+
if (param.required) required.push(param.name);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
server.tool(
|
|
40
|
+
cap.id,
|
|
41
|
+
cap.description,
|
|
42
|
+
properties,
|
|
43
|
+
async (args) => {
|
|
44
|
+
const url = new URL(cap.endpoint);
|
|
45
|
+
for (const [key, value] of Object.entries(args)) {
|
|
46
|
+
if (value !== void 0 && value !== null) {
|
|
47
|
+
url.searchParams.set(key, String(value));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
try {
|
|
51
|
+
const response = await fetch(url.toString(), {
|
|
52
|
+
method: cap.method ?? "GET",
|
|
53
|
+
headers: {
|
|
54
|
+
"Accept": "application/json",
|
|
55
|
+
"User-Agent": "agents-txt-mcp/0.1"
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
return {
|
|
60
|
+
content: [{ type: "text", text: `Error: HTTP ${response.status} ${response.statusText}` }]
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const data = await response.text();
|
|
64
|
+
return {
|
|
65
|
+
content: [{ type: "text", text: data }]
|
|
66
|
+
};
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return {
|
|
69
|
+
content: [{
|
|
70
|
+
type: "text",
|
|
71
|
+
text: `Error calling ${cap.endpoint}: ${err instanceof Error ? err.message : "Unknown error"}`
|
|
72
|
+
}]
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export {
|
|
80
|
+
createAgentsTxtServer
|
|
81
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { AgentsTxtClient } from "@agents-txt/core";
|
|
4
|
+
async function createAgentsTxtServer(targetUrl, options = {}) {
|
|
5
|
+
const client = new AgentsTxtClient();
|
|
6
|
+
let result = await client.discoverJSON(targetUrl);
|
|
7
|
+
if (!result.success) {
|
|
8
|
+
result = await client.discover(targetUrl);
|
|
9
|
+
}
|
|
10
|
+
if (!result.success || !result.document) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
`Failed to discover agents.txt at ${targetUrl}: ${result.errors.map((e) => e.message).join(", ")}`
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
const doc = result.document;
|
|
16
|
+
const server = new McpServer({
|
|
17
|
+
name: `agents-txt: ${doc.site.name}`,
|
|
18
|
+
version: "0.1.0"
|
|
19
|
+
});
|
|
20
|
+
for (const cap of doc.capabilities) {
|
|
21
|
+
if (cap.protocol === "REST") {
|
|
22
|
+
registerRestTool(server, cap, options);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return { server, document: doc };
|
|
26
|
+
}
|
|
27
|
+
function buildAuthHeaders(cap, options) {
|
|
28
|
+
const headers = {};
|
|
29
|
+
if (!cap.auth || cap.auth.type === "none") return headers;
|
|
30
|
+
switch (cap.auth.type) {
|
|
31
|
+
case "bearer-token":
|
|
32
|
+
if (options.bearerToken) {
|
|
33
|
+
headers["Authorization"] = `Bearer ${options.bearerToken}`;
|
|
34
|
+
}
|
|
35
|
+
break;
|
|
36
|
+
case "api-key":
|
|
37
|
+
if (options.apiKey) {
|
|
38
|
+
headers["X-API-Key"] = options.apiKey;
|
|
39
|
+
}
|
|
40
|
+
break;
|
|
41
|
+
case "oauth2":
|
|
42
|
+
if (options.bearerToken) {
|
|
43
|
+
headers["Authorization"] = `Bearer ${options.bearerToken}`;
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
function registerRestTool(server, cap, options) {
|
|
50
|
+
const properties = {};
|
|
51
|
+
const required = [];
|
|
52
|
+
if (cap.parameters) {
|
|
53
|
+
for (const param of cap.parameters) {
|
|
54
|
+
properties[param.name] = {
|
|
55
|
+
type: param.type === "integer" ? "number" : param.type,
|
|
56
|
+
description: param.description
|
|
57
|
+
};
|
|
58
|
+
if (param.required) required.push(param.name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
server.tool(
|
|
62
|
+
cap.id,
|
|
63
|
+
cap.description,
|
|
64
|
+
properties,
|
|
65
|
+
async (args) => {
|
|
66
|
+
const method = (cap.method ?? "GET").toUpperCase();
|
|
67
|
+
const url = new URL(cap.endpoint);
|
|
68
|
+
const authHeaders = buildAuthHeaders(cap, options);
|
|
69
|
+
const headers = {
|
|
70
|
+
"Accept": "application/json",
|
|
71
|
+
"User-Agent": "agents-txt-mcp/0.1",
|
|
72
|
+
...authHeaders
|
|
73
|
+
};
|
|
74
|
+
let body;
|
|
75
|
+
if (method === "GET" || method === "HEAD") {
|
|
76
|
+
for (const [key, value] of Object.entries(args)) {
|
|
77
|
+
if (value !== void 0 && value !== null) {
|
|
78
|
+
url.searchParams.set(key, String(value));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
const bodyArgs = {};
|
|
83
|
+
for (const [key, value] of Object.entries(args)) {
|
|
84
|
+
if (value === void 0 || value === null) continue;
|
|
85
|
+
const paramDef = cap.parameters?.find((p) => p.name === key);
|
|
86
|
+
if (paramDef?.in === "query") {
|
|
87
|
+
url.searchParams.set(key, String(value));
|
|
88
|
+
} else {
|
|
89
|
+
bodyArgs[key] = value;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (Object.keys(bodyArgs).length > 0) {
|
|
93
|
+
headers["Content-Type"] = "application/json";
|
|
94
|
+
body = JSON.stringify(bodyArgs);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const response = await fetch(url.toString(), {
|
|
99
|
+
method,
|
|
100
|
+
headers,
|
|
101
|
+
body
|
|
102
|
+
});
|
|
103
|
+
const data = await response.text();
|
|
104
|
+
if (!response.ok) {
|
|
105
|
+
return {
|
|
106
|
+
content: [{
|
|
107
|
+
type: "text",
|
|
108
|
+
text: `Error: HTTP ${response.status} ${response.statusText}
|
|
109
|
+
${data}`
|
|
110
|
+
}]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
content: [{ type: "text", text: data }]
|
|
115
|
+
};
|
|
116
|
+
} catch (err) {
|
|
117
|
+
return {
|
|
118
|
+
content: [{
|
|
119
|
+
type: "text",
|
|
120
|
+
text: `Error calling ${cap.endpoint}: ${err instanceof Error ? err.message : "Unknown error"}`
|
|
121
|
+
}]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export {
|
|
129
|
+
createAgentsTxtServer
|
|
130
|
+
};
|
package/dist/cli.cjs
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
// src/cli.ts
|
|
5
|
+
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
6
|
+
|
|
7
|
+
// src/server.ts
|
|
8
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
9
|
+
var import_core = require("@agents-txt/core");
|
|
10
|
+
async function createAgentsTxtServer(targetUrl2, options = {}) {
|
|
11
|
+
const client = new import_core.AgentsTxtClient();
|
|
12
|
+
let result = await client.discoverJSON(targetUrl2);
|
|
13
|
+
if (!result.success) {
|
|
14
|
+
result = await client.discover(targetUrl2);
|
|
15
|
+
}
|
|
16
|
+
if (!result.success || !result.document) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Failed to discover agents.txt at ${targetUrl2}: ${result.errors.map((e) => e.message).join(", ")}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const doc = result.document;
|
|
22
|
+
const server = new import_mcp.McpServer({
|
|
23
|
+
name: `agents-txt: ${doc.site.name}`,
|
|
24
|
+
version: "0.1.0"
|
|
25
|
+
});
|
|
26
|
+
for (const cap of doc.capabilities) {
|
|
27
|
+
if (cap.protocol === "REST") {
|
|
28
|
+
registerRestTool(server, cap, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return { server, document: doc };
|
|
32
|
+
}
|
|
33
|
+
function buildAuthHeaders(cap, options) {
|
|
34
|
+
const headers = {};
|
|
35
|
+
if (!cap.auth || cap.auth.type === "none") return headers;
|
|
36
|
+
switch (cap.auth.type) {
|
|
37
|
+
case "bearer-token":
|
|
38
|
+
if (options.bearerToken) {
|
|
39
|
+
headers["Authorization"] = `Bearer ${options.bearerToken}`;
|
|
40
|
+
}
|
|
41
|
+
break;
|
|
42
|
+
case "api-key":
|
|
43
|
+
if (options.apiKey) {
|
|
44
|
+
headers["X-API-Key"] = options.apiKey;
|
|
45
|
+
}
|
|
46
|
+
break;
|
|
47
|
+
case "oauth2":
|
|
48
|
+
if (options.bearerToken) {
|
|
49
|
+
headers["Authorization"] = `Bearer ${options.bearerToken}`;
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
return headers;
|
|
54
|
+
}
|
|
55
|
+
function registerRestTool(server, cap, options) {
|
|
56
|
+
const properties = {};
|
|
57
|
+
const required = [];
|
|
58
|
+
if (cap.parameters) {
|
|
59
|
+
for (const param of cap.parameters) {
|
|
60
|
+
properties[param.name] = {
|
|
61
|
+
type: param.type === "integer" ? "number" : param.type,
|
|
62
|
+
description: param.description
|
|
63
|
+
};
|
|
64
|
+
if (param.required) required.push(param.name);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
server.tool(
|
|
68
|
+
cap.id,
|
|
69
|
+
cap.description,
|
|
70
|
+
properties,
|
|
71
|
+
async (args) => {
|
|
72
|
+
const method = (cap.method ?? "GET").toUpperCase();
|
|
73
|
+
const url = new URL(cap.endpoint);
|
|
74
|
+
const authHeaders = buildAuthHeaders(cap, options);
|
|
75
|
+
const headers = {
|
|
76
|
+
"Accept": "application/json",
|
|
77
|
+
"User-Agent": "agents-txt-mcp/0.1",
|
|
78
|
+
...authHeaders
|
|
79
|
+
};
|
|
80
|
+
let body;
|
|
81
|
+
if (method === "GET" || method === "HEAD") {
|
|
82
|
+
for (const [key, value] of Object.entries(args)) {
|
|
83
|
+
if (value !== void 0 && value !== null) {
|
|
84
|
+
url.searchParams.set(key, String(value));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
const bodyArgs = {};
|
|
89
|
+
for (const [key, value] of Object.entries(args)) {
|
|
90
|
+
if (value === void 0 || value === null) continue;
|
|
91
|
+
const paramDef = cap.parameters?.find((p) => p.name === key);
|
|
92
|
+
if (paramDef?.in === "query") {
|
|
93
|
+
url.searchParams.set(key, String(value));
|
|
94
|
+
} else {
|
|
95
|
+
bodyArgs[key] = value;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (Object.keys(bodyArgs).length > 0) {
|
|
99
|
+
headers["Content-Type"] = "application/json";
|
|
100
|
+
body = JSON.stringify(bodyArgs);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const response = await fetch(url.toString(), {
|
|
105
|
+
method,
|
|
106
|
+
headers,
|
|
107
|
+
body
|
|
108
|
+
});
|
|
109
|
+
const data = await response.text();
|
|
110
|
+
if (!response.ok) {
|
|
111
|
+
return {
|
|
112
|
+
content: [{
|
|
113
|
+
type: "text",
|
|
114
|
+
text: `Error: HTTP ${response.status} ${response.statusText}
|
|
115
|
+
${data}`
|
|
116
|
+
}]
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
content: [{ type: "text", text: data }]
|
|
121
|
+
};
|
|
122
|
+
} catch (err) {
|
|
123
|
+
return {
|
|
124
|
+
content: [{
|
|
125
|
+
type: "text",
|
|
126
|
+
text: `Error calling ${cap.endpoint}: ${err instanceof Error ? err.message : "Unknown error"}`
|
|
127
|
+
}]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// src/cli.ts
|
|
135
|
+
var targetUrl = process.argv[2];
|
|
136
|
+
if (!targetUrl) {
|
|
137
|
+
console.error("Usage: agents-txt-mcp <url>");
|
|
138
|
+
console.error("Example: agents-txt-mcp https://example.com");
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
141
|
+
async function main() {
|
|
142
|
+
try {
|
|
143
|
+
const { server, document } = await createAgentsTxtServer(targetUrl);
|
|
144
|
+
console.error(`[agents-txt-mcp] Connected to: ${document.site.name}`);
|
|
145
|
+
console.error(`[agents-txt-mcp] Capabilities: ${document.capabilities.map((c) => c.id).join(", ")}`);
|
|
146
|
+
const transport = new import_stdio.StdioServerTransport();
|
|
147
|
+
await server.connect(transport);
|
|
148
|
+
} catch (err) {
|
|
149
|
+
console.error(`[agents-txt-mcp] Fatal:`, err instanceof Error ? err.message : err);
|
|
150
|
+
process.exit(1);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
main();
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
createAgentsTxtServer
|
|
4
|
+
} from "./chunk-TLN4YSVV.js";
|
|
5
|
+
|
|
6
|
+
// src/cli.ts
|
|
7
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
8
|
+
var targetUrl = process.argv[2];
|
|
9
|
+
if (!targetUrl) {
|
|
10
|
+
console.error("Usage: agents-txt-mcp <url>");
|
|
11
|
+
console.error("Example: agents-txt-mcp https://example.com");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
async function main() {
|
|
15
|
+
try {
|
|
16
|
+
const { server, document } = await createAgentsTxtServer(targetUrl);
|
|
17
|
+
console.error(`[agents-txt-mcp] Connected to: ${document.site.name}`);
|
|
18
|
+
console.error(`[agents-txt-mcp] Capabilities: ${document.capabilities.map((c) => c.id).join(", ")}`);
|
|
19
|
+
const transport = new StdioServerTransport();
|
|
20
|
+
await server.connect(transport);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
console.error(`[agents-txt-mcp] Fatal:`, err instanceof Error ? err.message : err);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
main();
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
createAgentsTxtServer: () => createAgentsTxtServer
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/server.ts
|
|
28
|
+
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
29
|
+
var import_core = require("@agents-txt/core");
|
|
30
|
+
async function createAgentsTxtServer(targetUrl, options = {}) {
|
|
31
|
+
const client = new import_core.AgentsTxtClient();
|
|
32
|
+
let result = await client.discoverJSON(targetUrl);
|
|
33
|
+
if (!result.success) {
|
|
34
|
+
result = await client.discover(targetUrl);
|
|
35
|
+
}
|
|
36
|
+
if (!result.success || !result.document) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Failed to discover agents.txt at ${targetUrl}: ${result.errors.map((e) => e.message).join(", ")}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
const doc = result.document;
|
|
42
|
+
const server = new import_mcp.McpServer({
|
|
43
|
+
name: `agents-txt: ${doc.site.name}`,
|
|
44
|
+
version: "0.1.0"
|
|
45
|
+
});
|
|
46
|
+
for (const cap of doc.capabilities) {
|
|
47
|
+
if (cap.protocol === "REST") {
|
|
48
|
+
registerRestTool(server, cap, options);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { server, document: doc };
|
|
52
|
+
}
|
|
53
|
+
function buildAuthHeaders(cap, options) {
|
|
54
|
+
const headers = {};
|
|
55
|
+
if (!cap.auth || cap.auth.type === "none") return headers;
|
|
56
|
+
switch (cap.auth.type) {
|
|
57
|
+
case "bearer-token":
|
|
58
|
+
if (options.bearerToken) {
|
|
59
|
+
headers["Authorization"] = `Bearer ${options.bearerToken}`;
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case "api-key":
|
|
63
|
+
if (options.apiKey) {
|
|
64
|
+
headers["X-API-Key"] = options.apiKey;
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case "oauth2":
|
|
68
|
+
if (options.bearerToken) {
|
|
69
|
+
headers["Authorization"] = `Bearer ${options.bearerToken}`;
|
|
70
|
+
}
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
return headers;
|
|
74
|
+
}
|
|
75
|
+
function registerRestTool(server, cap, options) {
|
|
76
|
+
const properties = {};
|
|
77
|
+
const required = [];
|
|
78
|
+
if (cap.parameters) {
|
|
79
|
+
for (const param of cap.parameters) {
|
|
80
|
+
properties[param.name] = {
|
|
81
|
+
type: param.type === "integer" ? "number" : param.type,
|
|
82
|
+
description: param.description
|
|
83
|
+
};
|
|
84
|
+
if (param.required) required.push(param.name);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
server.tool(
|
|
88
|
+
cap.id,
|
|
89
|
+
cap.description,
|
|
90
|
+
properties,
|
|
91
|
+
async (args) => {
|
|
92
|
+
const method = (cap.method ?? "GET").toUpperCase();
|
|
93
|
+
const url = new URL(cap.endpoint);
|
|
94
|
+
const authHeaders = buildAuthHeaders(cap, options);
|
|
95
|
+
const headers = {
|
|
96
|
+
"Accept": "application/json",
|
|
97
|
+
"User-Agent": "agents-txt-mcp/0.1",
|
|
98
|
+
...authHeaders
|
|
99
|
+
};
|
|
100
|
+
let body;
|
|
101
|
+
if (method === "GET" || method === "HEAD") {
|
|
102
|
+
for (const [key, value] of Object.entries(args)) {
|
|
103
|
+
if (value !== void 0 && value !== null) {
|
|
104
|
+
url.searchParams.set(key, String(value));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
const bodyArgs = {};
|
|
109
|
+
for (const [key, value] of Object.entries(args)) {
|
|
110
|
+
if (value === void 0 || value === null) continue;
|
|
111
|
+
const paramDef = cap.parameters?.find((p) => p.name === key);
|
|
112
|
+
if (paramDef?.in === "query") {
|
|
113
|
+
url.searchParams.set(key, String(value));
|
|
114
|
+
} else {
|
|
115
|
+
bodyArgs[key] = value;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (Object.keys(bodyArgs).length > 0) {
|
|
119
|
+
headers["Content-Type"] = "application/json";
|
|
120
|
+
body = JSON.stringify(bodyArgs);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
try {
|
|
124
|
+
const response = await fetch(url.toString(), {
|
|
125
|
+
method,
|
|
126
|
+
headers,
|
|
127
|
+
body
|
|
128
|
+
});
|
|
129
|
+
const data = await response.text();
|
|
130
|
+
if (!response.ok) {
|
|
131
|
+
return {
|
|
132
|
+
content: [{
|
|
133
|
+
type: "text",
|
|
134
|
+
text: `Error: HTTP ${response.status} ${response.statusText}
|
|
135
|
+
${data}`
|
|
136
|
+
}]
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
content: [{ type: "text", text: data }]
|
|
141
|
+
};
|
|
142
|
+
} catch (err) {
|
|
143
|
+
return {
|
|
144
|
+
content: [{
|
|
145
|
+
type: "text",
|
|
146
|
+
text: `Error calling ${cap.endpoint}: ${err instanceof Error ? err.message : "Unknown error"}`
|
|
147
|
+
}]
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
154
|
+
0 && (module.exports = {
|
|
155
|
+
createAgentsTxtServer
|
|
156
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { AgentsTxtDocument } from '@agents-txt/core';
|
|
3
|
+
|
|
4
|
+
interface ServerOptions {
|
|
5
|
+
/** Bearer token for authenticated endpoints. */
|
|
6
|
+
bearerToken?: string;
|
|
7
|
+
/** API key for authenticated endpoints. */
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create an MCP server that wraps an agents.txt-compliant website.
|
|
12
|
+
* Each declared capability becomes an MCP tool.
|
|
13
|
+
*/
|
|
14
|
+
declare function createAgentsTxtServer(targetUrl: string, options?: ServerOptions): Promise<{
|
|
15
|
+
server: McpServer;
|
|
16
|
+
document: AgentsTxtDocument;
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export { type ServerOptions, createAgentsTxtServer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { AgentsTxtDocument } from '@agents-txt/core';
|
|
3
|
+
|
|
4
|
+
interface ServerOptions {
|
|
5
|
+
/** Bearer token for authenticated endpoints. */
|
|
6
|
+
bearerToken?: string;
|
|
7
|
+
/** API key for authenticated endpoints. */
|
|
8
|
+
apiKey?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Create an MCP server that wraps an agents.txt-compliant website.
|
|
12
|
+
* Each declared capability becomes an MCP tool.
|
|
13
|
+
*/
|
|
14
|
+
declare function createAgentsTxtServer(targetUrl: string, options?: ServerOptions): Promise<{
|
|
15
|
+
server: McpServer;
|
|
16
|
+
document: AgentsTxtDocument;
|
|
17
|
+
}>;
|
|
18
|
+
|
|
19
|
+
export { type ServerOptions, createAgentsTxtServer };
|
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agents-txt/mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server that wraps any agents.txt-compliant website — instantly usable by Claude Desktop and other MCP clients",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"bin": {
|
|
10
|
+
"agents-txt-mcp": "./dist/cli.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"agents.txt",
|
|
24
|
+
"agents-txt",
|
|
25
|
+
"mcp",
|
|
26
|
+
"model-context-protocol",
|
|
27
|
+
"claude",
|
|
28
|
+
"claude-desktop",
|
|
29
|
+
"ai-agents",
|
|
30
|
+
"llm",
|
|
31
|
+
"well-known",
|
|
32
|
+
"capability-declaration",
|
|
33
|
+
"web-standard",
|
|
34
|
+
"anthropic",
|
|
35
|
+
"openai"
|
|
36
|
+
],
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "https://github.com/kaylacar/agents-txt.git",
|
|
40
|
+
"directory": "packages/mcp"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/kaylacar/agents-txt",
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/kaylacar/agents-txt/issues"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@agents-txt/core": "^0.1.0",
|
|
48
|
+
"@modelcontextprotocol/sdk": "^1.0.0"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@types/node": "^22.0.0",
|
|
52
|
+
"express": "^5.1.0",
|
|
53
|
+
"tsup": "^8.0.0",
|
|
54
|
+
"typescript": "^5.0.0",
|
|
55
|
+
"vitest": "^4.0.0",
|
|
56
|
+
"@agents-txt/express": "0.1.0"
|
|
57
|
+
},
|
|
58
|
+
"license": "MIT",
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "tsup src/index.ts src/cli.ts --format esm,cjs --dts",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"typecheck": "tsc --noEmit",
|
|
63
|
+
"clean": "rm -rf dist"
|
|
64
|
+
}
|
|
65
|
+
}
|