get-connect-uri
Generate a connection URI to link with a MetaMask wallet for secure blockchain interactions without exposing private keys.
Instructions
Get the connect URI to connect to a MetaMask wallet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- packages/metamask-mcp/src/tools/connect.ts:10-27 (registration)Registration of the 'get-connect-uri' tool in the registerConnectTools function, including schema (empty parameters) and inline execute handler that calls getMetaMaskConnectURI.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); return { content: [ { type: "text", text: JSONStringify({ uri, }), }, ], } }, });
- The core handler function that generates the MetaMask connect URI by setting up a headless metaMask connector with wagmi, listening for the display_uri message, and initiating a connection.async function getMetaMaskConnectURI(log: any) { 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) reject(error) }) }) }