Skip to main content
Glama

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
NameRequiredDescriptionDefault
codeYesThe Go code to share

Implementation Reference

  • 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); } };
  • 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'], }, },
  • 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;
  • 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; } };
  • 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) ); };
  • TypeScript type definition for share_go_code arguments.
    export type ShareGoCodeArgs = { readonly code: GoCode; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/samber/go-playground-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server