get-connect-uri
Generate a connection URI to link applications with MetaMask wallet for secure blockchain interactions.
Instructions
Get the connect URI to connect to a MetaMask wallet.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/connect.ts:11-28 (registration)Registration of the 'get-connect-uri' MCP tool, defining name, description, input schema (empty), and execute handler function.server.addTool({ name: "get-connect-uri", description: "Get the connect URI to connect to a MetaMask wallet.", parameters: z.object({}), execute: async (_, { log }) => { const uri = await getMetaMaskConnectURI(log, wagmiConfig); return { content: [ { type: "text", text: JSONStringify({ uri, }), }, ], }; }, });
- src/tools/connect.ts:15-27 (handler)Execute handler for 'get-connect-uri' tool: calls helper to get MetaMask connect URI and returns it as structured text content.execute: async (_, { log }) => { const uri = await getMetaMaskConnectURI(log, wagmiConfig); return { content: [ { type: "text", text: JSONStringify({ uri, }), }, ], }; },
- src/tools/connect.ts:14-14 (schema)Zod input schema for 'get-connect-uri': no parameters required.parameters: z.object({}),
- src/tools/connect.ts:48-74 (helper)Helper function implementing the core logic: creates headless MetaMask connector, listens for 'display_uri' event, and resolves the connect URI.async function getMetaMaskConnectURI(log: any, wagmiConfig: Config) { return new Promise((resolve, reject) => { const connectorFn = metaMask({ headless: true, }); const connector = wagmiConfig._internal.connectors.setup(connectorFn); connector.emitter.on("message", (payload) => { if (payload.type === "display_uri") { const uri = payload.data; resolve(uri); } }); connector.emitter.on("connect", (payload) => { log.debug("connect success!", payload.accounts); }); connector.emitter.on("error", (payload) => { log.error(payload.error); }); connect(wagmiConfig, { connector }) .catch((error) => { log.error("connect error: ", error); log.error(error.stack); reject(error); }); }); }
- src/tools/register-tools.ts:35-35 (registration)Top-level call to register connect tools, including 'get-connect-uri', during overall tools registration.registerConnectTools(server, wagmiConfig);