(toolName: string)
| 143 | * callers receive an error with isError: true. |
| 144 | */ |
| 145 | export function createMemberToolHandler(toolName: string) { |
| 146 | return async ( |
| 147 | args: Record<string, unknown>, |
| 148 | authContext?: MCPAuthContext, |
| 149 | ): Promise<{ content: Array<{ type: string; text: string }>; isError?: boolean }> => { |
| 150 | if (!authContext || authContext.sub === 'anonymous') { |
| 151 | return { |
| 152 | content: [{ type: 'text', text: 'Authentication required. Connect with OAuth to use this tool.' }], |
| 153 | isError: true, |
| 154 | }; |
| 155 | } |
| 156 | |
| 157 | const memberContext = mcpAuthToMemberContext(authContext); |
| 158 | const handlers = createMemberToolHandlers(memberContext); |
| 159 | const handler = handlers.get(toolName); |
| 160 | |
| 161 | if (!handler) { |
| 162 | logger.error({ toolName }, 'Member tool handler not found'); |
| 163 | return { |
| 164 | content: [{ type: 'text', text: JSON.stringify({ error: `Unknown tool: ${toolName}` }) }], |
| 165 | isError: true, |
| 166 | }; |
| 167 | } |
| 168 | |
| 169 | const result = await handler(args); |
| 170 | return { content: [{ type: 'text', text: result }] }; |
| 171 | }; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Create handlers for stateless tools (schema and property validation). |
no test coverage detected