# chonwai/askching_agent architecture

> Architecture diagram of the GitHub repository chonwai/askching_agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chonwai/askching_agent
- Repository: https://github.com/chonwai/askching_agent

## Overview

AskChing turns natural-language DeFi research requests into cited MCP results, or into a Grok-synthesized answer. The principal path is agent → MCP tool registration → research operation → live or fixture data source → Graph subgraphs → normalized, provenance-bearing results. Separate capabilities cover comparisons, market analysis, risk scans, trends, and lending/DEX yield discovery. The README documents both stdio and remote HTTP access. Some feature internals were not sampled, so those branches use documented relationships rather than inferred call chains.

Main entry points: [`packages/mcp-server/src/tools.ts`](https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/tools.ts) (Research tools), [`packages/shared/src/data-source.ts`](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/data-source.ts) (Market data source), [`packages/shared/src/yield-data-source.ts`](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-data-source.ts) (Yield data source), [`packages/grok-orchestrator/src/loop.ts`](https://github.com/chonwai/askching_agent/blob/main/packages/grok-orchestrator/src/loop.ts) (Grok tool loop)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Agent interfaces"]
  node_remote["Remote MCP API<br/>[mcp.ts]"]
  node_http["HTTP transport<br/>[http.ts]"]
  node_register["Tool registration<br/>[register.ts]"]
  node_stdio["Stdio server<br/>[index.ts]"]
  node_loop["Grok tool loop<br/>[loop.ts]"]
  node_llm["Completion client<br/>[client.ts]"]
end

subgraph group_research["Research operations"]
  node_tools["Research tools<br/>[tools.ts]"]
  node_analysis["Market analysis<br/>[analysis.ts]"]
  node_compare["Comparison logic<br/>[compare.ts]"]
  node_trends["Trend analysis<br/>[analysis.ts]"]
  node_schemas["Evidence schemas<br/>[schemas.ts]"]
end

subgraph group_market["Market data"]
  node_source["Market data source<br/>[data-source.ts]"]
  node_graph["Graph Gateway client<br/>[graph-client.ts]"]
  node_config["Protocol sources<br/>[source-config.ts]"]
  node_metrics["Metric registry<br/>[metrics.ts]"]
end

subgraph group_yield["Yield discovery"]
  node_yieldtools["Yield discovery<br/>[tools.ts]"]
  node_yieldsource["Yield data source"]
  node_yieldclient["DEX adapters<br/>[yield-client.ts]"]
  node_yieldsources["DEX source registry<br/>[yield-sources.ts]"]
  node_yieldfixtures["Yield fixtures<br/>[yield-fixtures.ts]"]
  node_yieldrank["Yield rankings<br/>[yield-discovery.ts]"]
end

node_agent(("MCP client"))
node_grok(("Grok or LLM"))
node_subgraphs[("The Graph subgraphs")]

node_agent -->|"sends requests"| node_remote
node_remote -.->|"routes requests"| node_http
node_http -->|"registers tools"| node_register
node_stdio -->|"registers tools"| node_register
node_agent -->|"uses stdio"| node_stdio
node_grok -->|"provides prompt"| node_loop
node_loop -->|"requests completion"| node_llm
node_loop -->|"dispatches calls"| node_tools
node_register -->|"invokes tools"| node_tools
node_tools -->|"fetches observations"| node_source
node_tools -.->|"builds findings"| node_analysis
node_tools -->|"ranks observations"| node_compare
node_tools -.->|"analyzes history"| node_trends
node_analysis -->|"validates results"| node_schemas
node_source -->|"selects protocols"| node_config
node_source -->|"resolves metrics"| node_metrics
node_source -->|"queries live data"| node_graph
node_graph -->|"queries markets"| node_subgraphs
node_yieldtools -.->|"requests opportunities"| node_yieldsource
node_yieldsource -->|"runs adapters"| node_yieldclient
node_yieldsource -->|"uses fixtures"| node_yieldfixtures
node_yieldsource -->|"selects venue"| node_yieldsources
node_yieldclient -->|"queries DEX data"| node_subgraphs
node_yieldtools -.->|"ranks opportunities"| node_yieldrank
node_yieldrank -->|"shapes results"| node_schemas

click node_remote "https://github.com/chonwai/askching_agent/blob/main/api/mcp.ts"
click node_http "https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/http.ts"
click node_register "https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/register.ts"
click node_stdio "https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/index.ts"
click node_loop "https://github.com/chonwai/askching_agent/blob/main/packages/grok-orchestrator/src/loop.ts"
click node_llm "https://github.com/chonwai/askching_agent/blob/main/packages/grok-orchestrator/src/client.ts"
click node_tools "https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/tools.ts"
click node_analysis "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/analysis.ts"
click node_compare "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/compare.ts"
click node_trends "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/analysis.ts"
click node_schemas "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/schemas.ts"
click node_source "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/data-source.ts"
click node_graph "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/graph-client.ts"
click node_config "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/source-config.ts"
click node_metrics "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/metrics.ts"
click node_yieldtools "https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/tools.ts"
click node_yieldsource "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-data-source.ts"
click node_yieldclient "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-client.ts"
click node_yieldsources "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-sources.ts"
click node_yieldfixtures "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-fixtures.ts"
click node_yieldrank "https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-discovery.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_remote,node_http,node_register,node_stdio,node_loop,node_llm,node_agent toneBlue
class node_tools,node_analysis,node_compare,node_trends,node_schemas,node_subgraphs toneAmber
class node_source,node_graph,node_config,node_metrics toneMint
class node_yieldtools,node_yieldsource,node_yieldclient,node_yieldsources,node_yieldfixtures,node_yieldrank toneRose
class node_grok toneIndigo
```

## Components

### Agent interfaces

- [Remote MCP API](https://github.com/chonwai/askching_agent/blob/main/api/mcp.ts): `api/mcp.ts`
- [HTTP transport](https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/http.ts): `packages/mcp-server/src/http.ts`
- [Tool registration](https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/register.ts): `packages/mcp-server/src/register.ts`
- [Stdio server](https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/index.ts): `packages/mcp-server/src/index.ts`
- [Grok tool loop](https://github.com/chonwai/askching_agent/blob/main/packages/grok-orchestrator/src/loop.ts): `packages/grok-orchestrator/src/loop.ts`
- [Completion client](https://github.com/chonwai/askching_agent/blob/main/packages/grok-orchestrator/src/client.ts): `packages/grok-orchestrator/src/client.ts`

### Research operations

- [Research tools](https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/tools.ts): `packages/mcp-server/src/tools.ts`
- [Market analysis](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/analysis.ts): `packages/shared/src/analysis.ts`
- [Comparison logic](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/compare.ts): `packages/shared/src/compare.ts`
- [Trend analysis](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/analysis.ts): `packages/shared/src/analysis.ts`
- [Evidence schemas](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/schemas.ts): `packages/shared/src/schemas.ts`

### Market data

- [Market data source](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/data-source.ts): `packages/shared/src/data-source.ts`
- [Graph Gateway client](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/graph-client.ts): `packages/shared/src/graph-client.ts`
- [Protocol sources](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/source-config.ts): `packages/shared/src/source-config.ts`
- [Metric registry](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/metrics.ts): `packages/shared/src/metrics.ts`

### Yield discovery

- [Yield discovery](https://github.com/chonwai/askching_agent/blob/main/packages/mcp-server/src/tools.ts): `packages/mcp-server/src/tools.ts`
- [Yield data source](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-data-source.ts): `packages/shared/src/yield-data-source.ts`
- [DEX adapters](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-client.ts): `packages/shared/src/yield-client.ts`
- [DEX source registry](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-sources.ts): `packages/shared/src/yield-sources.ts`
- [Yield fixtures](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-fixtures.ts): `packages/shared/src/yield-fixtures.ts`
- [Yield rankings](https://github.com/chonwai/askching_agent/blob/main/packages/shared/src/yield-discovery.ts): `packages/shared/src/yield-discovery.ts`

### Other components

- **MCP client**
- **Grok or LLM**
- **The Graph subgraphs**

## Connections

- MCP client → Remote MCP API: sends requests (evidence: `README.md`)
- Remote MCP API → HTTP transport: routes requests
- HTTP transport → Tool registration: registers tools (evidence: `packages/mcp-server/src/http.ts`)
- Stdio server → Tool registration: registers tools (evidence: `packages/mcp-server/src/index.ts`)
- MCP client → Stdio server: uses stdio (evidence: `README.md`)
- Grok or LLM → Grok tool loop: provides prompt (evidence: `README.md`)
- Grok tool loop → Completion client: requests completion (evidence: `packages/grok-orchestrator/src/client.ts`)
- Grok tool loop → Research tools: dispatches calls (evidence: `packages/grok-orchestrator/src/loop.ts`)
- Tool registration → Research tools: invokes tools (evidence: `packages/mcp-server/src/register.ts`)
- Research tools → Market data source: fetches observations (evidence: `packages/mcp-server/src/tools.ts`)
- Research tools → Market analysis: builds findings
- Research tools → Comparison logic: ranks observations (evidence: `packages/mcp-server/src/tools.ts`)
- Research tools → Trend analysis: analyzes history
- Market analysis → Evidence schemas: validates results (evidence: `packages/shared/src/analysis.ts`)
- Market data source → Protocol sources: selects protocols (evidence: `packages/shared/src/data-source.ts`)
- Market data source → Metric registry: resolves metrics (evidence: `packages/shared/src/data-source.ts`)
- Market data source → Graph Gateway client: queries live data (evidence: `packages/shared/src/data-source.ts`)
- Graph Gateway client → The Graph subgraphs: queries markets (evidence: `README.md`)
- Yield discovery → Yield data source: requests opportunities
- Yield data source → DEX adapters: runs adapters (evidence: `packages/shared/src/yield-data-source.ts`)
- Yield data source → Yield fixtures: uses fixtures (evidence: `packages/shared/src/yield-data-source.ts`)
- Yield data source → DEX source registry: selects venue (evidence: `packages/shared/src/yield-data-source.ts`)
- DEX adapters → The Graph subgraphs: queries DEX data (evidence: `README.md`)
- Yield discovery → Yield rankings: ranks opportunities
- Yield rankings → Evidence schemas: shapes results (evidence: `packages/shared/src/yield-discovery.ts`)
