Skip to content

Commit b3ab647

Browse files
committed
refactor: Update tool type references and add prompt listing methods in BaseConnector
1 parent 564a0f4 commit b3ab647

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

src/adapters/langchain_adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type {
44
CallToolResult,
55
EmbeddedResource,
66
ImageContent,
7-
Tool as McpTool,
7+
Tool as MCPTool,
88
TextContent,
99
} from '@modelcontextprotocol/sdk/types.js'
1010
import type { ZodTypeAny } from 'zod'
@@ -78,7 +78,7 @@ export class LangChainAdapter extends BaseAdapter<StructuredToolInterface> {
7878
* Convert a single MCP tool specification into a LangChainJS structured tool.
7979
*/
8080
protected convertTool(
81-
mcpTool: McpTool,
81+
mcpTool: MCPTool,
8282
connector: BaseConnector,
8383
): StructuredToolInterface | null {
8484
// Filter out disallowed tools early.

src/agents/mcp_agent.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { BaseLanguageModelInterface, LanguageModelLike } from '@langchain/c
22
import type {
33
BaseMessage,
44
} from '@langchain/core/messages'
5-
import type { StructuredToolInterface } from '@langchain/core/tools'
5+
import type { StructuredToolInterface, ToolInterface } from '@langchain/core/tools'
66
import type { AgentFinish, AgentStep } from 'langchain/agents'
77
import type { MCPClient } from '../client.js'
88
import type { BaseConnector } from '../connectors/base.js'
@@ -54,7 +54,6 @@ export class MCPAgent {
5454
llm: BaseLanguageModelInterface
5555
client?: MCPClient
5656
connectors?: BaseConnector[]
57-
serverName?: string
5857
maxSteps?: number
5958
autoInitialize?: boolean
6059
memoryEnabled?: boolean
@@ -328,7 +327,7 @@ export class MCPAgent {
328327
try {
329328
logger.debug('Starting agent step execution')
330329
const nextStepOutput = await this.agentExecutor._takeNextStep(
331-
nameToToolMap,
330+
nameToToolMap as Record<string, ToolInterface>,
332331
inputs,
333332
intermediateSteps,
334333
)

src/connectors/base.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ export abstract class BaseConnector {
117117
return { content: res.content, mimeType: res.mimeType }
118118
}
119119

120+
async listPrompts() {
121+
if (!this.client) {
122+
throw new Error('MCP client is not connected')
123+
}
124+
125+
logger.debug('Listing prompt')
126+
return await this.client.listPrompts()
127+
}
128+
129+
async getPrompt(name: string, args: Record<string, any>) {
130+
if (!this.client) {
131+
throw new Error('MCP client is not connected')
132+
}
133+
134+
logger.debug(`Getting prompt ${name}`)
135+
return await this.client.getPrompt({ name, arguments: args })
136+
}
137+
120138
/** Send a raw request through the client. */
121139
async request(method: string, params: Record<string, any> | null = null, options?: RequestOptions) {
122140
if (!this.client) {

0 commit comments

Comments
 (0)