# Bug Fix: MCP Tool Response Format
## Issue
The MCP tools were returning only `content` with text, but VS Code's MCP client expects tools with an `outputSchema` to also return `structuredContent` that matches the schema.
## Root Cause
According to the MCP TypeScript SDK documentation, when a tool has an `outputSchema` defined, the response should include:
1. `content`: Array of content items (text, images, etc.) for display
2. `structuredContent`: The actual structured data matching the `outputSchema`
## Files Fixed
All 9 MCP tool files were updated:
- `src/tools/search-stories.ts`
- `src/tools/search-by-date.ts`
- `src/tools/search-comments.ts`
- `src/tools/get-front-page.ts`
- `src/tools/get-latest-stories.ts`
- `src/tools/get-ask-hn.ts`
- `src/tools/get-show-hn.ts`
- `src/tools/get-story.ts`
- `src/tools/get-user.ts`
## Changes Made
### Before
```typescript
return {
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
};
```
### After
```typescript
return {
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
structuredContent: result as unknown as Record<string, unknown>,
};
```
### Error Handling
Also improved error handling to return structured error objects:
```typescript
if (error instanceof HNError) {
const errorContent = { error: error.message };
return {
content: [{ type: 'text', text: JSON.stringify(errorContent) }],
isError: true,
};
}
```
## Testing
- ✅ TypeScript compilation passes without errors
- ✅ MCP server starts successfully
- ✅ All 9 tools are registered correctly
- ✅ Tools list shows proper input/output schemas
## Next Steps
1. Reload VS Code window to pick up the rebuilt server
2. Test with GitHub Copilot: "Search Hacker News for stories about machine learning"
3. The MCP tools should now work correctly with structured responses
## Reference
- MCP TypeScript SDK: https://github.com/modelcontextprotocol/typescript-sdk
- Example from SDK showing `structuredContent` usage in tool responses