@cyanheads/pubmed-mcp-server 1.0.16 → 1.1.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/dist/config/index.d.ts +8 -20
- package/dist/config/index.js +16 -45
- package/dist/index.js +77 -29
- package/dist/mcp-server/server.d.ts +3 -2
- package/dist/mcp-server/server.js +16 -14
- package/dist/mcp-server/tools/fetchPubMedContent/logic.js +2 -1
- package/dist/mcp-server/tools/generatePubMedChart/registration.js +2 -2
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/citationFormatter.js +2 -1
- package/dist/mcp-server/tools/getPubMedArticleConnections/logic/elinkHandler.js +2 -1
- package/dist/mcp-server/tools/pubmedResearchAgent/logic/inputSchema.js +1 -1
- package/dist/mcp-server/tools/pubmedResearchAgent/logic/planOrchestrator.js +21 -10
- package/dist/mcp-server/tools/searchPubMedArticles/logic.js +2 -1
- package/dist/mcp-server/transports/authentication/authContext.d.ts +33 -0
- package/dist/mcp-server/transports/authentication/authContext.js +24 -0
- package/dist/mcp-server/transports/authentication/authMiddleware.d.ts +21 -15
- package/dist/mcp-server/transports/authentication/authMiddleware.js +51 -69
- package/dist/mcp-server/transports/authentication/authUtils.d.ts +18 -0
- package/dist/mcp-server/transports/authentication/authUtils.js +45 -0
- package/dist/mcp-server/transports/authentication/oauthMiddleware.d.ts +24 -0
- package/dist/mcp-server/transports/authentication/oauthMiddleware.js +109 -0
- package/dist/mcp-server/transports/authentication/types.d.ts +17 -0
- package/dist/mcp-server/transports/authentication/types.js +5 -0
- package/dist/mcp-server/transports/httpTransport.d.ts +5 -4
- package/dist/mcp-server/transports/httpTransport.js +177 -143
- package/dist/services/NCBI/ncbiCoreApiClient.js +0 -5
- package/dist/services/NCBI/ncbiRequestQueueManager.js +2 -4
- package/dist/services/NCBI/ncbiResponseHandler.js +0 -3
- package/dist/services/NCBI/ncbiService.d.ts +1 -1
- package/dist/services/NCBI/ncbiService.js +11 -4
- package/dist/utils/internal/logger.js +10 -30
- package/package.json +20 -7
- package/dist/services/index.d.ts +0 -7
- package/dist/services/index.js +0 -7
- package/dist/services/llm-providers/index.d.ts +0 -7
- package/dist/services/llm-providers/index.js +0 -7
- package/dist/services/llm-providers/llmFactory.d.ts +0 -69
- package/dist/services/llm-providers/llmFactory.js +0 -132
- package/dist/services/llm-providers/openRouter/index.d.ts +0 -6
- package/dist/services/llm-providers/openRouter/index.js +0 -7
- package/dist/services/llm-providers/openRouter/openRouterProvider.d.ts +0 -99
- package/dist/services/llm-providers/openRouter/openRouterProvider.js +0 -329
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyanheads/pubmed-mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "A Model Context Protocol (MCP) server enabling AI agents to intelligently search, retrieve, and analyze biomedical literature from PubMed via NCBI E-utilities. Built on the mcp-ts-template for robust, production-ready performance.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -33,10 +33,11 @@
|
|
|
33
33
|
"start:client-cli": "node dist/mcp-client/cli/mcp-client-cli.js"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@
|
|
36
|
+
"@hono/node-server": "^1.14.4",
|
|
37
37
|
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
38
|
+
"@node-oauth/oauth2-server": "^5.2.0",
|
|
38
39
|
"@types/jsonwebtoken": "^9.0.9",
|
|
39
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.0.1",
|
|
40
41
|
"@types/sanitize-html": "^2.16.0",
|
|
41
42
|
"@types/validator": "13.15.1",
|
|
42
43
|
"axios": "^1.9.0",
|
|
@@ -46,10 +47,12 @@
|
|
|
46
47
|
"cli-table3": "^0.6.5",
|
|
47
48
|
"dotenv": "^16.5.0",
|
|
48
49
|
"express": "^5.1.0",
|
|
49
|
-
"fast-xml-parser": "^5.2.
|
|
50
|
+
"fast-xml-parser": "^5.2.5",
|
|
51
|
+
"hono": "^4.7.11",
|
|
50
52
|
"ignore": "^7.0.5",
|
|
53
|
+
"jose": "^6.0.11",
|
|
51
54
|
"jsonwebtoken": "^9.0.2",
|
|
52
|
-
"openai": "^5.
|
|
55
|
+
"openai": "^5.3.0",
|
|
53
56
|
"partial-json": "^0.1.7",
|
|
54
57
|
"sanitize-html": "^2.17.0",
|
|
55
58
|
"tiktoken": "^1.0.21",
|
|
@@ -61,7 +64,7 @@
|
|
|
61
64
|
"winston": "^3.17.0",
|
|
62
65
|
"winston-daily-rotate-file": "^5.0.0",
|
|
63
66
|
"yargs": "^18.0.0",
|
|
64
|
-
"zod": "^3.25.
|
|
67
|
+
"zod": "^3.25.64"
|
|
65
68
|
},
|
|
66
69
|
"keywords": [
|
|
67
70
|
"mcp",
|
|
@@ -84,6 +87,16 @@
|
|
|
84
87
|
],
|
|
85
88
|
"author": "cyanheads <casey@caseyjhand.com> (https://github.com/cyanheads/pubmed-mcp-server#readme)",
|
|
86
89
|
"license": "Apache-2.0",
|
|
90
|
+
"funding": [
|
|
91
|
+
{
|
|
92
|
+
"type": "github",
|
|
93
|
+
"url": "https://github.com/sponsors/cyanheads"
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
"type": "buy_me_a_coffee",
|
|
97
|
+
"url": "https://www.buymeacoffee.com/cyanheads"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
87
100
|
"publishConfig": {
|
|
88
101
|
"access": "public"
|
|
89
102
|
},
|
|
@@ -91,7 +104,7 @@
|
|
|
91
104
|
"node": ">=16.0.0"
|
|
92
105
|
},
|
|
93
106
|
"devDependencies": {
|
|
94
|
-
"@types/express": "^5.0.
|
|
107
|
+
"@types/express": "^5.0.3",
|
|
95
108
|
"@types/js-yaml": "^4.0.9",
|
|
96
109
|
"js-yaml": "^4.1.0",
|
|
97
110
|
"prettier": "^3.5.3",
|
package/dist/services/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main barrel file for all services.
|
|
3
|
-
* This file re-exports all service modules, providing a single entry point
|
|
4
|
-
* for accessing various services within the application.
|
|
5
|
-
* @module src/services/index
|
|
6
|
-
*/
|
|
7
|
-
export * from "./llm-providers/index.js";
|
package/dist/services/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Main barrel file for all services.
|
|
3
|
-
* This file re-exports all service modules, providing a single entry point
|
|
4
|
-
* for accessing various services within the application.
|
|
5
|
-
* @module src/services/index
|
|
6
|
-
*/
|
|
7
|
-
export * from "./llm-providers/index.js";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Barrel file for LLM provider services.
|
|
3
|
-
* This file re-exports all services related to different Large Language Model providers,
|
|
4
|
-
* making them easily accessible from a single import path.
|
|
5
|
-
* @module src/services/llm-providers/index
|
|
6
|
-
*/
|
|
7
|
-
export * from "./openRouter/index.js";
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Barrel file for LLM provider services.
|
|
3
|
-
* This file re-exports all services related to different Large Language Model providers,
|
|
4
|
-
* making them easily accessible from a single import path.
|
|
5
|
-
* @module src/services/llm-providers/index
|
|
6
|
-
*/
|
|
7
|
-
export * from "./openRouter/index.js"; // Changed to export from the new barrel file
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Factory for creating LLM client instances.
|
|
3
|
-
* Provides a centralized way to instantiate clients for different LLM providers
|
|
4
|
-
* like OpenRouter and Google Gemini, handling API key configuration and
|
|
5
|
-
* basic client setup.
|
|
6
|
-
* @module src/services/llm-providers/llmFactory
|
|
7
|
-
*/
|
|
8
|
-
import { GoogleGenAI } from "@google/genai";
|
|
9
|
-
import OpenAI from "openai";
|
|
10
|
-
import { RequestContext } from "../../utils/index.js";
|
|
11
|
-
/**
|
|
12
|
-
* Defines the supported LLM providers.
|
|
13
|
-
*/
|
|
14
|
-
export type LlmProviderType = "openrouter" | "gemini";
|
|
15
|
-
/**
|
|
16
|
-
* Options for configuring the OpenRouter client.
|
|
17
|
-
*/
|
|
18
|
-
export interface OpenRouterClientOptions {
|
|
19
|
-
apiKey?: string;
|
|
20
|
-
baseURL?: string;
|
|
21
|
-
siteUrl?: string;
|
|
22
|
-
siteName?: string;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Options for configuring the Gemini client using @google/genai.
|
|
26
|
-
* The factory will return a GoogleGenAI instance.
|
|
27
|
-
* Vertex AI specific options are included here.
|
|
28
|
-
*/
|
|
29
|
-
export interface GeminiClientOptions {
|
|
30
|
-
apiKey?: string;
|
|
31
|
-
useVertexAi?: boolean;
|
|
32
|
-
project?: string;
|
|
33
|
-
location?: string;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Union type for all LLM client options.
|
|
37
|
-
*/
|
|
38
|
-
export type LlmClientOptions = OpenRouterClientOptions | GeminiClientOptions;
|
|
39
|
-
/**
|
|
40
|
-
* LLM Factory class to create and configure LLM clients.
|
|
41
|
-
*/
|
|
42
|
-
declare class LlmFactory {
|
|
43
|
-
/**
|
|
44
|
-
* Creates and returns an LLM client instance for the specified provider.
|
|
45
|
-
*
|
|
46
|
-
* @param provider - The LLM provider to create a client for.
|
|
47
|
-
* @param context - The request context for logging.
|
|
48
|
-
* @param options - Optional provider-specific configuration options.
|
|
49
|
-
* @returns A Promise resolving to an instance of OpenAI (for OpenRouter)
|
|
50
|
-
* or GoogleGenAI (for Gemini).
|
|
51
|
-
* @throws {McpError} If the provider is unsupported or API key/config is missing.
|
|
52
|
-
*/
|
|
53
|
-
getLlmClient(provider: LlmProviderType, context: RequestContext, options?: LlmClientOptions): Promise<OpenAI | GoogleGenAI>;
|
|
54
|
-
/**
|
|
55
|
-
* Creates an OpenAI client configured for OpenRouter.
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
private createOpenRouterClient;
|
|
59
|
-
/**
|
|
60
|
-
* Creates a GoogleGenAI client for Gemini, supporting standard API key or Vertex AI.
|
|
61
|
-
* @private
|
|
62
|
-
*/
|
|
63
|
-
private createGeminiClient;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Singleton instance of the LlmFactory.
|
|
67
|
-
*/
|
|
68
|
-
export declare const llmFactory: LlmFactory;
|
|
69
|
-
export {};
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Factory for creating LLM client instances.
|
|
3
|
-
* Provides a centralized way to instantiate clients for different LLM providers
|
|
4
|
-
* like OpenRouter and Google Gemini, handling API key configuration and
|
|
5
|
-
* basic client setup.
|
|
6
|
-
* @module src/services/llm-providers/llmFactory
|
|
7
|
-
*/
|
|
8
|
-
import { GoogleGenAI } from "@google/genai"; // Updated import path
|
|
9
|
-
import OpenAI from "openai";
|
|
10
|
-
import { config } from "../../config/index.js";
|
|
11
|
-
import { BaseErrorCode, McpError } from "../../types-global/errors.js";
|
|
12
|
-
import { logger } from "../../utils/index.js";
|
|
13
|
-
/**
|
|
14
|
-
* LLM Factory class to create and configure LLM clients.
|
|
15
|
-
*/
|
|
16
|
-
class LlmFactory {
|
|
17
|
-
/**
|
|
18
|
-
* Creates and returns an LLM client instance for the specified provider.
|
|
19
|
-
*
|
|
20
|
-
* @param provider - The LLM provider to create a client for.
|
|
21
|
-
* @param context - The request context for logging.
|
|
22
|
-
* @param options - Optional provider-specific configuration options.
|
|
23
|
-
* @returns A Promise resolving to an instance of OpenAI (for OpenRouter)
|
|
24
|
-
* or GoogleGenAI (for Gemini).
|
|
25
|
-
* @throws {McpError} If the provider is unsupported or API key/config is missing.
|
|
26
|
-
*/
|
|
27
|
-
async getLlmClient(provider, context, options) {
|
|
28
|
-
// Return type changed for Gemini
|
|
29
|
-
const operation = `LlmFactory.getLlmClient.${provider}`;
|
|
30
|
-
logger.info(`[${operation}] Requesting LLM client`, {
|
|
31
|
-
...context,
|
|
32
|
-
provider,
|
|
33
|
-
});
|
|
34
|
-
switch (provider) {
|
|
35
|
-
case "openrouter":
|
|
36
|
-
return this.createOpenRouterClient(context, options);
|
|
37
|
-
case "gemini":
|
|
38
|
-
return this.createGeminiClient(context, options);
|
|
39
|
-
default:
|
|
40
|
-
logger.error(`[${operation}] Unsupported LLM provider requested: ${provider}`, context);
|
|
41
|
-
throw new McpError(BaseErrorCode.CONFIGURATION_ERROR, `Unsupported LLM provider: ${provider}`, { operation, provider });
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates an OpenAI client configured for OpenRouter.
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
createOpenRouterClient(context, options) {
|
|
49
|
-
const operation = "LlmFactory.createOpenRouterClient";
|
|
50
|
-
const apiKey = options?.apiKey || config.openrouterApiKey;
|
|
51
|
-
const baseURL = options?.baseURL || "https://openrouter.ai/api/v1";
|
|
52
|
-
const siteUrl = options?.siteUrl || config.openrouterAppUrl;
|
|
53
|
-
const siteName = options?.siteName || config.openrouterAppName;
|
|
54
|
-
if (!apiKey) {
|
|
55
|
-
logger.error(`[${operation}] OPENROUTER_API_KEY is not set.`, context);
|
|
56
|
-
throw new McpError(BaseErrorCode.CONFIGURATION_ERROR, "OpenRouter API key is not configured.", { operation });
|
|
57
|
-
}
|
|
58
|
-
try {
|
|
59
|
-
const client = new OpenAI({
|
|
60
|
-
baseURL,
|
|
61
|
-
apiKey,
|
|
62
|
-
defaultHeaders: {
|
|
63
|
-
"HTTP-Referer": siteUrl,
|
|
64
|
-
"X-Title": siteName,
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
logger.info(`[${operation}] OpenRouter client created successfully.`, context);
|
|
68
|
-
return client;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
logger.error(`[${operation}] Failed to create OpenRouter client`, {
|
|
72
|
-
...context,
|
|
73
|
-
error: error.message,
|
|
74
|
-
});
|
|
75
|
-
throw new McpError(BaseErrorCode.INITIALIZATION_FAILED, `Failed to initialize OpenRouter client: ${error.message}`, { operation, cause: error });
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Creates a GoogleGenAI client for Gemini, supporting standard API key or Vertex AI.
|
|
80
|
-
* @private
|
|
81
|
-
*/
|
|
82
|
-
createGeminiClient(context, options) {
|
|
83
|
-
const operation = "LlmFactory.createGeminiClient";
|
|
84
|
-
if (options?.useVertexAi) {
|
|
85
|
-
if (!options.project || !options.location) {
|
|
86
|
-
logger.error(`[${operation}] Vertex AI project and location are required when useVertexAi is true.`, context);
|
|
87
|
-
throw new McpError(BaseErrorCode.CONFIGURATION_ERROR, "Vertex AI project and location must be configured if useVertexAi is true.", { operation });
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
// For Vertex AI, apiKey in GoogleGenAI constructor is optional if ADC are set up.
|
|
91
|
-
// The SDK handles ADC automatically if apiKey is not provided.
|
|
92
|
-
const clientConfig = {
|
|
93
|
-
project: options.project,
|
|
94
|
-
location: options.location,
|
|
95
|
-
vertexai: true,
|
|
96
|
-
};
|
|
97
|
-
if (options.apiKey) {
|
|
98
|
-
// Allow API key to be passed for Vertex if specific auth needed
|
|
99
|
-
clientConfig.apiKey = options.apiKey;
|
|
100
|
-
}
|
|
101
|
-
const genAI = new GoogleGenAI(clientConfig);
|
|
102
|
-
logger.info(`[${operation}] GoogleGenAI client for Vertex AI created successfully.`, context);
|
|
103
|
-
return genAI;
|
|
104
|
-
}
|
|
105
|
-
catch (error) {
|
|
106
|
-
logger.error(`[${operation}] Failed to create Gemini client for Vertex AI`, { ...context, error: error.message });
|
|
107
|
-
throw new McpError(BaseErrorCode.INITIALIZATION_FAILED, `Failed to initialize Gemini client for Vertex AI: ${error.message}`, { operation, cause: error });
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
// Standard Gemini API key authentication
|
|
112
|
-
const apiKey = options?.apiKey || config.geminiApiKey;
|
|
113
|
-
if (!apiKey) {
|
|
114
|
-
logger.error(`[${operation}] GEMINI_API_KEY is not set for standard API usage.`, context);
|
|
115
|
-
throw new McpError(BaseErrorCode.CONFIGURATION_ERROR, "Gemini API key is not configured for standard API usage.", { operation });
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
const genAI = new GoogleGenAI({ apiKey });
|
|
119
|
-
logger.info(`[${operation}] GoogleGenAI client (standard API key) created successfully.`, context);
|
|
120
|
-
return genAI;
|
|
121
|
-
}
|
|
122
|
-
catch (error) {
|
|
123
|
-
logger.error(`[${operation}] Failed to create Gemini client (standard API key)`, { ...context, error: error.message });
|
|
124
|
-
throw new McpError(BaseErrorCode.INITIALIZATION_FAILED, `Failed to initialize Gemini client (standard API key): ${error.message}`, { operation, cause: error });
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Singleton instance of the LlmFactory.
|
|
131
|
-
*/
|
|
132
|
-
export const llmFactory = new LlmFactory();
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Barrel file for the OpenRouter provider service.
|
|
3
|
-
* Exports the OpenRouterProvider class and any related types.
|
|
4
|
-
* @module services/llm-providers/openRouter/index
|
|
5
|
-
*/
|
|
6
|
-
export * from "./openRouterProvider.js";
|
|
7
|
-
// Add other exports from this module if any in the future
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { OpenRouterClientOptions } from "../llmFactory.js";
|
|
2
|
-
import { ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParamsNonStreaming, ChatCompletionCreateParamsStreaming } from "openai/resources/chat/completions";
|
|
3
|
-
import { Stream } from "openai/streaming";
|
|
4
|
-
import { OperationContext, RequestContext } from "../../../utils/internal/requestContext.js";
|
|
5
|
-
/**
|
|
6
|
-
* Defines the parameters for an OpenRouter chat completion request.
|
|
7
|
-
* This type extends standard OpenAI chat completion parameters and includes
|
|
8
|
-
* OpenRouter-specific fields.
|
|
9
|
-
*
|
|
10
|
-
* @property top_k - OpenRouter specific: Sample from the k most likely next tokens.
|
|
11
|
-
* @property min_p - OpenRouter specific: Minimum probability for a token to be considered.
|
|
12
|
-
* @property transforms - OpenRouter specific: Apply transformations to the request or response.
|
|
13
|
-
* @property models - OpenRouter specific: A list of models to use, often for fallback or routing.
|
|
14
|
-
* @property route - OpenRouter specific: Specifies routing strategy, e.g., 'fallback'.
|
|
15
|
-
* @property provider - OpenRouter specific: Provider-specific parameters or routing preferences.
|
|
16
|
-
* @property stream - If true, the response will be a stream of `ChatCompletionChunk` objects.
|
|
17
|
-
* If false or undefined, a single `ChatCompletion` object is returned.
|
|
18
|
-
*/
|
|
19
|
-
export type OpenRouterChatParams = (ChatCompletionCreateParamsNonStreaming | ChatCompletionCreateParamsStreaming) & {
|
|
20
|
-
top_k?: number;
|
|
21
|
-
min_p?: number;
|
|
22
|
-
transforms?: string[];
|
|
23
|
-
models?: string[];
|
|
24
|
-
route?: "fallback";
|
|
25
|
-
provider?: Record<string, any>;
|
|
26
|
-
};
|
|
27
|
-
/**
|
|
28
|
-
* Service class for interacting with the OpenRouter API.
|
|
29
|
-
* Uses the OpenAI SDK for chat completions, configured for OpenRouter.
|
|
30
|
-
* Handles API key management, default headers, model-specific parameter adjustments,
|
|
31
|
-
* and provides methods for chat completions and listing models.
|
|
32
|
-
*/
|
|
33
|
-
declare class OpenRouterProvider {
|
|
34
|
-
/**
|
|
35
|
-
* The OpenAI SDK client instance configured for OpenRouter.
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
private client?;
|
|
39
|
-
/**
|
|
40
|
-
* Current status of the OpenRouter service.
|
|
41
|
-
* - `unconfigured`: API key is missing.
|
|
42
|
-
* - `initializing`: Constructor is running.
|
|
43
|
-
* - `ready`: Client initialized successfully and service is usable.
|
|
44
|
-
* - `error`: An error occurred during initialization.
|
|
45
|
-
*/
|
|
46
|
-
status: "unconfigured" | "initializing" | "ready" | "error";
|
|
47
|
-
/**
|
|
48
|
-
* Stores any error that occurred during client initialization.
|
|
49
|
-
* @private
|
|
50
|
-
*/
|
|
51
|
-
private initializationError;
|
|
52
|
-
/**
|
|
53
|
-
* Constructs an `OpenRouterProvider` instance.
|
|
54
|
-
* Initializes the OpenAI client for OpenRouter if an API key is provided.
|
|
55
|
-
* Sets default headers required by OpenRouter.
|
|
56
|
-
* @param apiKey - The OpenRouter API key. If undefined, the service remains 'unconfigured'.
|
|
57
|
-
* @param parentOpContext - Optional parent operation context for linked logging.
|
|
58
|
-
*/
|
|
59
|
-
constructor(options?: OpenRouterClientOptions, parentOpContext?: OperationContext);
|
|
60
|
-
/**
|
|
61
|
-
* Checks if the service is ready to make API calls.
|
|
62
|
-
* @param operation - The name of the operation attempting to use the service.
|
|
63
|
-
* @param context - The request context for logging.
|
|
64
|
-
* @throws {McpError} If the service is not ready.
|
|
65
|
-
* @private
|
|
66
|
-
*/
|
|
67
|
-
private checkReady;
|
|
68
|
-
/**
|
|
69
|
-
* Creates a chat completion using the OpenRouter API.
|
|
70
|
-
* Can return either a single response or a stream of chunks.
|
|
71
|
-
* Applies rate limiting and handles model-specific parameter adjustments.
|
|
72
|
-
*
|
|
73
|
-
* @param params - Parameters for the chat completion request.
|
|
74
|
-
* @param context - Request context for logging, error handling, and rate limiting.
|
|
75
|
-
* @returns A promise resolving with either a `ChatCompletion` or a `Stream<ChatCompletionChunk>`.
|
|
76
|
-
* @throws {McpError} If service not ready, rate limit exceeded, or API call fails.
|
|
77
|
-
*/
|
|
78
|
-
chatCompletion(params: OpenRouterChatParams, context: RequestContext): Promise<ChatCompletion | Stream<ChatCompletionChunk>>;
|
|
79
|
-
/**
|
|
80
|
-
* Lists available models from the OpenRouter API.
|
|
81
|
-
* Makes a direct `fetch` call to the `/models` endpoint.
|
|
82
|
-
*
|
|
83
|
-
* @param context - Request context for logging and error handling.
|
|
84
|
-
* @returns A promise resolving with the JSON response from the OpenRouter API.
|
|
85
|
-
* @throws {McpError} If the service is not ready, or if the API call fails.
|
|
86
|
-
*/
|
|
87
|
-
listModels(context: RequestContext): Promise<any>;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Singleton instance of the `OpenRouterProvider`.
|
|
91
|
-
* Initialized with the OpenRouter API key from application configuration.
|
|
92
|
-
*/
|
|
93
|
-
declare const openRouterProviderInstance: OpenRouterProvider;
|
|
94
|
-
export { openRouterProviderInstance as openRouterProvider };
|
|
95
|
-
/**
|
|
96
|
-
* Exporting the type of the OpenRouterProvider class for use in dependency injection
|
|
97
|
-
* or for type hinting elsewhere in the application.
|
|
98
|
-
*/
|
|
99
|
-
export type { OpenRouterProvider };
|