share_go_code
Generate shareable URLs for Go code snippets to enable easy distribution and collaboration on programming examples.
Instructions
Share Go code and get a shareable URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The Go code to share |
Implementation Reference
- src/mcp-server.ts:230-246 (handler)MCP tool handler for 'share_go_code': extracts code argument, calls underlying client.shareCode(), formats success/error response with shareable URL.const createShareGoCodeHandler = (client: ReturnType<typeof createGoPlaygroundClient>) => async (args: ShareGoCodeArgs): Promise<MCPToolResponse> => { try { const { code } = args; const shareUrl = await client.shareCode(code); const responseText = shareUrl ? `✅ Code shared successfully!\n\n**Share URL:** ${shareUrl}` : '❌ Failed to share code. Please try again.'; return createSuccessResponse(responseText); } catch (error) { console.error('Error in handleShareGoCode:', error); return createErrorResponse(error); } };
- src/mcp-server.ts:69-82 (schema)Tool schema registration: defines name, description, and inputSchema for 'share_go_code' returned by listTools.{ name: TOOL_NAMES.SHARE_GO_CODE, description: 'Share Go code and get a shareable URL', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The Go code to share', }, }, required: ['code'], }, },
- src/mcp-server.ts:301-306 (registration)Registration of share_go_code handler in the router's handlers map.[TOOL_NAMES.RUN_GO_CODE]: createRunGoCodeHandler(client), [TOOL_NAMES.SHARE_GO_CODE]: createShareGoCodeHandler(client), [TOOL_NAMES.RUN_AND_SHARE_GO_CODE]: createRunAndShareGoCodeHandler(client), [TOOL_NAMES.READ_GO_PLAYGROUND_URL]: createReadGoPlaygroundUrlHandler(client), [TOOL_NAMES.EXECUTE_GO_PLAYGROUND_URL]: createExecuteGoPlaygroundUrlHandler(client), } as const;
- src/go-playground-client.ts:161-199 (helper)Core helper function implementing code sharing: validates Go code, POSTs to Go Playground /share API, constructs frontend share URL (https://go.dev/play/p/{id}).export const shareGoCode = (config: Partial<GoPlaygroundConfig> = {}) => async (code: string): Promise<ShareUrl | null> => { // Validate input const validationResult = validateGoCode(code); if (!validationResult.success) { console.error( 'Invalid Go code for sharing:', validationResult.error.message ); return null; } const finalConfig = { ...createDefaultConfig(), ...config }; const client = createHttpClient(finalConfig); try { const request: GoPlaygroundShareRequest = { body: validationResult.data, }; const response = await client.post<GoPlaygroundShareResponse>( '/share', request.body, { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, } ); const shareId = response.data; // Use the frontend URL for sharing, not the API URL return createShareUrl(`${finalConfig.frontendUrl}/p/${shareId}`); } catch (error) { console.error('Failed to share code:', error); return null; } };
- src/types.ts:171-178 (schema)Runtime type guard for validating share_go_code input arguments.export const isShareGoCodeArgs = (args: unknown): args is ShareGoCodeArgs => { return ( typeof args === 'object' && args !== null && 'code' in args && isGoCode((args as Record<string, unknown>).code) ); };
- src/types.ts:75-77 (schema)TypeScript type definition for share_go_code arguments.export type ShareGoCodeArgs = { readonly code: GoCode; };