@agentfare/mcp-server 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/README.md +7 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +43 -0
- package/dist/server.js.map +1 -0
- package/package.json +24 -0
package/README.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
5
|
+
const server_js_1 = require("./server.js");
|
|
6
|
+
const server = (0, server_js_1.createServer)();
|
|
7
|
+
const transport = new stdio_js_1.StdioServerTransport();
|
|
8
|
+
server.connect(transport).catch(console.error);
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,wEAAiF;AACjF,2CAA2C;AAE3C,MAAM,MAAM,GAAG,IAAA,wBAAY,GAAE,CAAC;AAC9B,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;AAC7C,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { TrackingDatabase } from "@agentfare/core";
|
|
3
|
+
import { ModelRegistry } from "@agentfare/models";
|
|
4
|
+
export interface ServerDeps {
|
|
5
|
+
db: TrackingDatabase;
|
|
6
|
+
registry: ModelRegistry;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Create an MCP Server instance with all tool handlers registered.
|
|
10
|
+
* Accepts explicit dependencies for testability.
|
|
11
|
+
* When no deps provided, uses production singletons.
|
|
12
|
+
*/
|
|
13
|
+
export declare function createServer(deps?: Partial<ServerDeps>): McpServer;
|
|
14
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAuD,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAE,aAAa,EAAa,MAAM,mBAAmB,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,gBAAgB,CAAC;IACrB,QAAQ,EAAE,aAAa,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,SAAS,CAiClE"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createServer = createServer;
|
|
4
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const core_1 = require("@agentfare/core");
|
|
7
|
+
const models_1 = require("@agentfare/models");
|
|
8
|
+
/**
|
|
9
|
+
* Create an MCP Server instance with all tool handlers registered.
|
|
10
|
+
* Accepts explicit dependencies for testability.
|
|
11
|
+
* When no deps provided, uses production singletons.
|
|
12
|
+
*/
|
|
13
|
+
function createServer(deps) {
|
|
14
|
+
const db = deps?.db ?? new core_1.TrackingDatabase((0, models_1.getDbPath)());
|
|
15
|
+
const registry = deps?.registry ?? new models_1.ModelRegistry();
|
|
16
|
+
// Register exit cleanup only for the production singleton path
|
|
17
|
+
if (!deps?.db) {
|
|
18
|
+
process.on("exit", () => { try {
|
|
19
|
+
db.close();
|
|
20
|
+
}
|
|
21
|
+
catch { } });
|
|
22
|
+
}
|
|
23
|
+
const server = new mcp_js_1.McpServer({ name: "agentfare", version: "0.1.0" });
|
|
24
|
+
server.tool("get_cost_report", "获取 AgentFare 成本报告", { timeRange: zod_1.z.string().optional().describe("时间范围 (1d, 7d, 30d)") }, async (params) => {
|
|
25
|
+
const report = (0, core_1.generateReport)(db, params.timeRange);
|
|
26
|
+
return { content: [{ type: "text", text: JSON.stringify(report, null, 2) }] };
|
|
27
|
+
});
|
|
28
|
+
server.tool("models_list", "列出所有可用模型", {}, async () => {
|
|
29
|
+
const models = registry.getAll().map((m) => ({
|
|
30
|
+
id: m.id, provider: m.provider, tier: m.tier,
|
|
31
|
+
pricing: { input: `$${m.pricing.inputPerMillion}/MTok`, output: `$${m.pricing.outputPerMillion}/MTok` },
|
|
32
|
+
}));
|
|
33
|
+
return { content: [{ type: "text", text: JSON.stringify(models, null, 2) }] };
|
|
34
|
+
});
|
|
35
|
+
server.tool("optimize_pipeline", "优化模型组合", { pipeline: zod_1.z.string().describe("Pipeline YAML") }, async (params) => {
|
|
36
|
+
const pipeline = (0, core_1.parsePipelineYAML)(params.pipeline);
|
|
37
|
+
const costFn = (combo) => Object.values(combo).reduce((sum, m) => { const entry = registry.get(m); return sum + (entry ? entry.pricing.inputPerMillion + entry.pricing.outputPerMillion : 10); }, 0);
|
|
38
|
+
const results = (0, core_1.bruteForceSearch)(pipeline, costFn);
|
|
39
|
+
return { content: [{ type: "text", text: JSON.stringify(results.slice(0, 5), null, 2) }] };
|
|
40
|
+
});
|
|
41
|
+
return server;
|
|
42
|
+
}
|
|
43
|
+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AAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7K,MAAM,OAAO,GAAG,IAAA,uBAAgB,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACtG,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentfare/mcp-server",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@agentfare/core": "workspace:*",
|
|
15
|
+
"@agentfare/models": "workspace:*",
|
|
16
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
17
|
+
"zod": "^4.4.3"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/node": "^22.19.19",
|
|
21
|
+
"typescript": "^5.8",
|
|
22
|
+
"vitest": "^3.2"
|
|
23
|
+
}
|
|
24
|
+
}
|