Skip to content

Commit 42dbd3c

Browse files
committed
Adding Brownina model full example flow
1 parent 98835fe commit 42dbd3c

File tree

1 file changed

+11
-14
lines changed
  • provider/modelcontextprotocoltools

1 file changed

+11
-14
lines changed

provider/modelcontextprotocoltools/index.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { basename } from 'node:path'
22
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
33
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
44
import {
5-
CreateMessageRequestSchema,
6-
ProgressNotificationSchema,
75
CallToolResultSchema,
86

97
} from '@modelcontextprotocol/sdk/types.js'
@@ -28,7 +26,7 @@ async function createClient(
2826
): Promise<Client> {
2927
const client = new Client(
3028
{
31-
name: 'mcp-inspector',
29+
name: 'mcp-tool',
3230
version: '0.0.1',
3331
},
3432
{
@@ -44,15 +42,6 @@ async function createClient(
4442
args: [mcpProviderFile, ...mcpProviderArgs],
4543
})
4644
await client.connect(transport)
47-
48-
client.setNotificationHandler(ProgressNotificationSchema, notification => {
49-
console.log('got MCP notif', notification)
50-
})
51-
52-
client.setRequestHandler(CreateMessageRequestSchema, request => {
53-
console.log('got MCP request', request)
54-
return { _meta: {} }
55-
})
5645
return client
5746
}
5847

@@ -61,6 +50,7 @@ class MCPToolsProxy implements Provider {
6150
private toolSchemas: Map<string, any> = new Map()
6251
private ajv = new Ajv()
6352

53+
// Gets the Metadata for the MCP Tools Provider
6454
async meta(_params: MetaParams, settings: ProviderSettings): Promise<MetaResult> {
6555
const nodeCommand: string = (settings.nodeCommand as string) ?? 'node'
6656
const mcpProviderUri = settings['mcp.provider.uri'] as string
@@ -90,6 +80,7 @@ class MCPToolsProxy implements Provider {
9080
}
9181
}
9282

83+
// Gets Lists All the tools available in the MCP Provider along with their schemas
9384
async mentions?(params: MentionsParams, _settings: ProviderSettings): Promise<MentionsResult> {
9485
if (!this.mcpClient) {
9586
return []
@@ -119,6 +110,7 @@ class MCPToolsProxy implements Provider {
119110
const prefixMatches: Mention[] = []
120111
const substringMatches: Mention[] = []
121112

113+
// Filters the tools based on the query
122114
for (const mention of mentions) {
123115
const title = mention.title.toLowerCase()
124116
if (title.startsWith(query)) {
@@ -128,14 +120,16 @@ class MCPToolsProxy implements Provider {
128120
}
129121
}
130122

123+
// Combines the prefix and substring matches
131124
return [...prefixMatches, ...substringMatches]
132125
}
133126

134-
// Add a method to get the stored schema
127+
// Retrieves the schema for a tool from the Map using the tool name as key
135128
getToolSchema(toolName: string): any {
136129
return JSON.parse(this.toolSchemas.get(toolName) as string)
137130
}
138131

132+
// Calls the tool with the provided input and returns the result
139133
async items?(params: ItemsParams, _settings: ProviderSettings): Promise<ItemsResult> {
140134
if (!this.mcpClient) {
141135
return []
@@ -145,6 +139,7 @@ class MCPToolsProxy implements Provider {
145139
const toolName = params.mention?.title
146140
const toolInput = params.mention?.data
147141

142+
// Validates the tool input against the stored schema
148143
if (toolName && toolInput) {
149144
const schema = this.getToolSchema(toolName)
150145
if (schema) {
@@ -156,6 +151,7 @@ class MCPToolsProxy implements Provider {
156151
}
157152
}
158153

154+
// Calls the tool with the provided input
159155
const response = await mcpClient.request(
160156
{
161157
method: 'tools/call' as const,
@@ -166,12 +162,13 @@ class MCPToolsProxy implements Provider {
166162
},
167163
CallToolResultSchema,
168164
)
165+
169166
const contents = response.content
170167
const items: Item[] = []
171168
for (const content of contents) {
172169
if (content.text) {
173170
items.push({
174-
title: (content.uri as string) ?? '',
171+
title: (toolName as string) ?? '',
175172
ai: {
176173
content: (content.text as string) ?? '',
177174
},

0 commit comments

Comments
 (0)