@aggc/or-info 0.2.8 → 0.2.9
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/bin/or-info.mjs +4 -1
- package/mcp/server.mjs +49 -4
- package/package.json +1 -1
package/bin/or-info.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import { InvalidArgumentError, program } from 'commander';
|
|
3
4
|
import chalk from 'chalk';
|
|
5
|
+
|
|
6
|
+
const { version } = createRequire(import.meta.url)('../package.json');
|
|
4
7
|
import { fetchModels, findModel, pricePerMillion, contextLength } from '../lib/openrouter.mjs';
|
|
5
8
|
import { getElo, getAllElo, loadLeaderboard } from '../lib/lmarena.mjs';
|
|
6
9
|
import { rankModels } from '../lib/scorer.mjs';
|
|
@@ -40,7 +43,7 @@ async function apiKey() {
|
|
|
40
43
|
program
|
|
41
44
|
.name('or-info')
|
|
42
45
|
.description('OpenRouter model info: prices, benchmarks, context and comparisons')
|
|
43
|
-
.version(
|
|
46
|
+
.version(version)
|
|
44
47
|
.option('--mcp', 'Start MCP server (stdio transport)');
|
|
45
48
|
|
|
46
49
|
// ── models ─────────────────────────────────────────────────────────────────
|
package/mcp/server.mjs
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
1
2
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
3
5
|
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
4
6
|
import { fetchModels, findModel, pricePerMillion, contextLength, modelTags } from '../lib/openrouter.mjs';
|
|
5
7
|
import { getElo, getAllElo, loadLeaderboard } from '../lib/lmarena.mjs';
|
|
6
8
|
import { rankModels } from '../lib/scorer.mjs';
|
|
7
9
|
import { getApiKey } from '../lib/secrets.mjs';
|
|
8
10
|
|
|
11
|
+
const { version } = createRequire(import.meta.url)('../package.json');
|
|
12
|
+
|
|
9
13
|
const MODEL_SUMMARY_SCHEMA = {
|
|
10
14
|
type: 'object',
|
|
11
15
|
properties: {
|
|
@@ -322,14 +326,15 @@ async function handleTool(name, args) {
|
|
|
322
326
|
return errorContent(`Unknown tool: ${name}`);
|
|
323
327
|
}
|
|
324
328
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
{ name: 'or-info', version
|
|
329
|
+
function makeServer() {
|
|
330
|
+
return new Server(
|
|
331
|
+
{ name: 'or-info', version },
|
|
328
332
|
{ capabilities: { tools: {} } }
|
|
329
333
|
);
|
|
334
|
+
}
|
|
330
335
|
|
|
336
|
+
function wireHandlers(server) {
|
|
331
337
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
|
|
332
|
-
|
|
333
338
|
server.setRequestHandler(CallToolRequestSchema, async (req) => {
|
|
334
339
|
const { name, arguments: args } = req.params;
|
|
335
340
|
try {
|
|
@@ -339,6 +344,11 @@ export async function startMcp() {
|
|
|
339
344
|
return errorContent(safe);
|
|
340
345
|
}
|
|
341
346
|
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export async function startMcp() {
|
|
350
|
+
const server = makeServer();
|
|
351
|
+
wireHandlers(server);
|
|
342
352
|
|
|
343
353
|
const transport = new StdioServerTransport();
|
|
344
354
|
await server.connect(transport);
|
|
@@ -352,3 +362,38 @@ export async function startMcp() {
|
|
|
352
362
|
});
|
|
353
363
|
}
|
|
354
364
|
}
|
|
365
|
+
|
|
366
|
+
export async function startHttpMcp() {
|
|
367
|
+
const { createServer } = await import('node:http');
|
|
368
|
+
const port = Number(process.env.PORT) || 8000;
|
|
369
|
+
|
|
370
|
+
// Bridge config values Smithery may inject from smithery.yaml configSchema.
|
|
371
|
+
// Smithery passes schema properties as-is or uppercased depending on version.
|
|
372
|
+
if (!process.env.OPENROUTER_API_KEY) {
|
|
373
|
+
process.env.OPENROUTER_API_KEY = process.env.api_key ?? process.env.API_KEY ?? '';
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
377
|
+
const server = makeServer();
|
|
378
|
+
wireHandlers(server);
|
|
379
|
+
await server.connect(transport);
|
|
380
|
+
|
|
381
|
+
const serverCard = JSON.stringify({
|
|
382
|
+
serverInfo: { name: 'or-info', version },
|
|
383
|
+
tools: CANONICAL_TOOLS.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })),
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
createServer(async (req, res) => {
|
|
387
|
+
if (req.url?.startsWith('/mcp')) {
|
|
388
|
+
await transport.handleRequest(req, res);
|
|
389
|
+
} else if (req.method === 'GET' && req.url === '/.well-known/mcp/server-card.json') {
|
|
390
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
391
|
+
res.end(serverCard);
|
|
392
|
+
} else {
|
|
393
|
+
res.writeHead(404);
|
|
394
|
+
res.end();
|
|
395
|
+
}
|
|
396
|
+
}).listen(port, () => {
|
|
397
|
+
process.stderr.write(`or-info HTTP MCP listening on port ${port}\n`);
|
|
398
|
+
});
|
|
399
|
+
}
|