share_go_code
Generate a shareable URL from Go code to enable distribution and collaboration.
Instructions
Share Go code and get a shareable URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The Go code to share |
Implementation Reference
- src/mcp-server.ts:69-82 (registration)Tool registration for share_go_code in the MCP server tool definitions
{ 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:230-246 (handler)MCP handler for share_go_code - calls client.shareCode and formats the response
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/types.ts:75-77 (schema)Type definition for share_go_code arguments
export type ShareGoCodeArgs = { readonly code: GoCode; }; - src/types.ts:171-178 (schema)Type guard for ShareGoCodeArgs runtime validation
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/go-playground-client.ts:161-199 (helper)Core shareGoCode function that calls the Go Playground /share API and returns a shareable URL
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; } };