You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Adding New Subgraph Endpoints](#adding-new-subgraph-endpoints)
23
28
-[Detailed Setup Guide](#detailed-setup-guide)
@@ -45,6 +50,7 @@
45
50
- ✅ **Contract Hot Reload**: Your frontend auto-adapts to your smart contract as you edit it
46
51
- 🤖 **AI-Powered Chat Interface**: Natural language interaction with blockchain data and smart contracts
47
52
- 📊 **GraphQL Integration**: Query blockchain data through The Graph protocol
53
+
- 🔌 **MCP Integration**: Direct connection to The Graph's official Model Context Protocol server
48
54
- 🪝 **[Custom hooks](https://docs.scaffoldeth.io/hooks/)**: Collection of React hooks wrapper around [wagmi](https://wagmi.sh/)
49
55
- 🧱 [**Components**](https://docs.scaffoldeth.io/components/): Collection of common web3 components
50
56
- 🔥 **Burner Wallet & Local Faucet**: Quickly test your application
@@ -131,15 +137,24 @@ Detailed explanations of the foundational pieces of this application.
131
137
-**Tool Definition**: Actions are described with a name, description, and a Zod schema for input validation, making them understandable and usable by the AI.
132
138
-**Invocation**: The AI decides which tool to use based on the user's query and the provided descriptions. The `app/api/chat/route.ts` orchestrates this.
-**Functionality**: Enables the AI agent to fetch data from The Graph Protocol by constructing and executing GraphQL queries.
142
+
-**Functionality**: Connects directly to The Graph's official Model Context Protocol (MCP) server, providing advanced subgraph discovery and querying capabilities.
143
+
-**Key Aspects**:
144
+
-**Official MCP Server**: Connects to `https://subgraphs.mcp.thegraph.com/sse` using Server-Sent Events (SSE) transport.
145
+
-**Dynamic Subgraph Discovery**: Search and discover subgraphs by keyword or contract address.
146
+
-**Schema Introspection**: Retrieve GraphQL schemas for any subgraph to understand available entities and fields.
147
+
-**Flexible Querying**: Execute GraphQL queries against subgraphs using subgraph ID, deployment ID, or IPFS hash.
-**Functionality**: Static GraphQL integration with pre-configured subgraph endpoints (maintained for backward compatibility).
137
152
-**Key Aspects**:
138
153
-**Subgraph Endpoints**: Manages a list of pre-configured (and dynamically accessible via API key) subgraph URLs (e.g., Uniswap, Aave).
139
154
-**Dynamic Queries**: The AI can request queries against any of the configured subgraphs.
140
155
-**Type Safety**: Uses Zod schemas to validate the structure of GraphQL queries formulated by the agent.
141
156
142
-
4.**Token API Integration** (Proxy: `app/api/token-proxy/route.ts`, Utilities: `utils/chat/agentkit/token-api/utils.ts`, Schemas: `utils/chat/agentkit/token-api/schemas.ts`)
157
+
5.**Token API Integration** (Proxy: `app/api/token-proxy/route.ts`, Utilities: `utils/chat/agentkit/token-api/utils.ts`, Schemas: `utils/chat/agentkit/token-api/schemas.ts`)
143
158
-**Functionality**: Provides access to comprehensive token data (balances, transfers, metadata, market prices, etc.) from an external token API service (e.g., The Graph's Token API).
144
159
-**Key Aspects**:
145
160
-**Proxy Server**: A Next.js API route (`/api/token-proxy`) that securely forwards requests to the external token API. This is crucial for hiding API keys from the client-side.
@@ -150,7 +165,55 @@ Detailed explanations of the foundational pieces of this application.
150
165
151
166
This section highlights critical files and their roles within the application architecture.
-**Purpose**: Themainbackendendpointthatreceivesusermessagesfromthechatinterface, orchestratestheAI's response generation using AgentKit and OpenAI, and streams the response back.
236
299
-**CoreLogic**:
@@ -287,7 +350,7 @@ This section highlights critical files and their roles within the application ar
287
350
-Providesreal-timeresponsestreaming.
288
351
-**BestPractice**: Craftclearandcomprehensivesystemprompts. ThisiscrucialforguidingtheAI's behavior and ensuring it uses the available tools correctly. Regularly update the prompt as new tools or capabilities are added. Secure this endpoint appropriately.
289
352
290
-
3.**ChatInterface** (`app/chat/page.tsx`)
353
+
4.**ChatInterface** (`app/chat/page.tsx`)
291
354
292
355
-**Purpose**: ThefrontendReactcomponentthatrendersthechatUI, handlesuserinput, displaysmessages (bothuser's and AI's), andvisualizestoolcallsandresults.
293
356
-**CoreLogic**:
@@ -371,7 +434,7 @@ This section highlights critical files and their roles within the application ar
371
434
-Errorstatemanagementanddisplay.
372
435
-**BestPractice**: ProvideclearvisualfeedbacktotheuserabouttheAI's status (e.g., "AI is thinking...", "AI is using tool X..."). Ensure the UI gracefully handles and displays errors returned from the backend or from tool executions.
-**Clarity**: The`path`parametershouldclearlymaptotheexternalAPI's own path structure. For example, if the external API endpoint is `https://token-api.thegraph.com/v1/tokens/mainnet/0xContract/transfers?limit=10`, then `path` would be `v1/tokens/mainnet/0xContract/transfers` and `limit=10` would be a forwarded query parameter.
-**BestPractice**: Eachutilityfunction should have a clear, single responsibility. Input parameters and output structures should be robustly typed and validated using Zod. Implement comprehensive error handling and logging.
- **Schema Not Found**: "Schema not available for deployment ID 0x..."
1029
+
1030
+
**Best Practices:**
1031
+
1032
+
1. **Always provide chain parameter** when using `getContractSubgraphs`
1033
+
2. **Use specific subgraph identifiers** (ID, deployment ID, or IPFS hash) for querying
1034
+
3. **Handle pagination** for large result sets in queries
1035
+
4. **Validate GraphQL syntax** before execution
1036
+
5. **Check schema** before constructing complex queries
1037
+
807
1038
### Available Subgraphs
808
1039
809
1040
The integration includes several pre-configured subgraph endpoints:
@@ -995,10 +1226,11 @@ Here's a step-by-step guide to add a new subgraph endpoint (e.g., Compound Finan
995
1226
996
1227
Proper configuration of environment variables is crucial for the application to run correctly and securely. Store these in a `.env.local` file at the root of your `packages/nextjs` directory. **Never commit your `.env.local` file to version control.**
997
1228
998
-
1. **`GRAPH_API_KEY`** (For The Graph Protocol - `graph-querier.ts`)
1229
+
1. **`GRAPH_API_KEY`** (For The Graph Protocol - Required for both legacy and MCP integrations)
999
1230
1000
1231
- ⚠️ Use a development key with limited permissions for querying subgraphs.
1001
-
- _Note: This key is used by `graph-querier.ts` for accessing The Graph subgraphs._
1232
+
- _Note: This key is used by both `graph-querier.ts` (legacy) and `graph-mcp-provider.ts` (MCP) for accessing The Graph services._
1233
+
- _MCP Usage: Used as Bearer token for authentication with The Graph's MCP server at `https://subgraphs.mcp.thegraph.com/sse`_
@@ -1286,7 +1518,15 @@ A multi-layered approach to ensure reliability.
1286
1518
-Verifyvariableformatting
1287
1519
-ForTokenAPI, ensurethe`path`parameterin`app/api/token-proxy/route.ts`iscorrectlyformedandthatallrequiredparametersforthespecificexternalAPIendpointarebeingpassed. Checktheproxy's server-side logs for details on the outgoing request.
0 commit comments