Installation
npm install @gizatech/mcp-server
The package depends on @gizatech/agent-sdk and @modelcontextprotocol/sdk — both are installed automatically.
Quick Start
The simplest programmatic usage — one function call:
import { serve } from '@gizatech/mcp-server';
// Reads env vars, registers all tools, starts stdio transport
await serve();
For HTTP transport:
await serve({ transport: 'http', port: 3001 });
You don’t have to register all 22 tools. Import only what you need:
import { Giza, Chain } from '@gizatech/agent-sdk';
import {
createGizaServer,
resolveConfig,
portfolioTools,
protocolTools,
walletTools,
} from '@gizatech/mcp-server';
const config = resolveConfig({
giza: new Giza({ chain: Chain.BASE }),
tools: [...walletTools, ...protocolTools, ...portfolioTools],
});
const server = createGizaServer(config);
await server.stdio();
Available tool groups:
| Import | Tools Included |
|---|
walletTools | connect_wallet, disconnect_wallet |
accountTools | create_smart_account, get_smart_account |
protocolTools | get_protocols, get_tokens, get_stats, get_tvl |
lifecycleTools | activate_agent, deactivate_agent, top_up, run_agent |
portfolioTools | get_portfolio, get_performance, get_apr, get_deposits |
financialTools | withdraw, get_withdrawal_status, get_transactions, get_fees |
rewardsTools | claim_rewards |
optimizerTools | optimize |
allTools | All of the above combined |
Always include walletTools when including any wallet-dependent group (lifecycle, portfolio, financial, rewards). Without it, the LLM has no way to connect a wallet.
Custom System Prompt
Override the default DeFi assistant prompt:
const config = resolveConfig({
giza: new Giza({ chain: Chain.BASE }),
systemPrompt: `You are a savings assistant for Acme Finance.
Help users deposit funds and monitor their yield.
Always be concise and use plain language.`,
});
const server = createGizaServer(config);
await server.stdio();
The system prompt is registered as an MCP prompt named system that clients can retrieve.
Tools are plain objects with a Zod schema and an async handler. You can create your own and register them alongside the built-in tools:
import { z } from 'zod';
import type { ToolDefinition } from '@gizatech/mcp-server';
import { textResult } from '@gizatech/mcp-server';
const myCustomTool: ToolDefinition = {
name: 'get_greeting',
description: 'Return a personalized greeting for the user.',
inputSchema: z.object({
name: z.string().min(1, 'Name is required'),
}),
async handler(_ctx, input) {
const name = input['name'] as string;
return textResult(`Hello, ${name}! Welcome to Giza.`);
},
};
Register it:
import { createGizaServer, resolveConfig, allTools } from '@gizatech/mcp-server';
const config = resolveConfig({
giza: new Giza({ chain: Chain.BASE }),
tools: [...allTools, myCustomTool],
});
const server = createGizaServer(config);
await server.stdio();
interface ToolDefinition {
name: string;
description: string;
inputSchema: z.ZodObject<z.ZodRawShape>;
handler: (ctx: ToolContext, input: Record<string, unknown>) => Promise<ToolResult>;
}
The ToolContext provides:
| Field | Type | Description |
|---|
giza | Giza | SDK instance for making API calls |
walletStore | WalletContextStore | Session-based wallet storage |
sessionId | string | Current session identifier |
Result Helpers
Use the built-in helpers to format tool responses:
import { textResult, jsonResult, errorResult } from '@gizatech/mcp-server';
// Plain text response
return textResult('Operation completed successfully.');
// JSON response (pretty-printed)
return jsonResult({ apr: 5.42, protocol: 'aave' });
// Error response
return errorResult('Invalid token address.');
Using the GizaServer Class Directly
For lower-level control, use GizaServer directly instead of createGizaServer:
import { GizaServer } from '@gizatech/mcp-server';
const server = new GizaServer(resolvedConfig);
// Access the underlying McpServer for advanced MCP features
server.mcp.resource(/* ... */);
// Connect transport
await server.stdio();
// or
await server.http({ port: 3000 });
Exports Reference
Everything exported by @gizatech/mcp-server:
| Export | Type | Description |
|---|
serve | Function | One-call convenience: resolve config, create server, connect transport |
createGizaServer | Function | Create a GizaServer from a resolved config |
GizaServer | Class | MCP server wrapping the Giza SDK |
resolveConfig | Function | Resolve partial config using env vars and defaults |
allTools | ToolDefinition[] | All 23 built-in tools |
walletTools | ToolDefinition[] | Wallet connection tools |
accountTools | ToolDefinition[] | Smart account tools |
protocolTools | ToolDefinition[] | Protocol discovery tools |
lifecycleTools | ToolDefinition[] | Agent lifecycle tools |
portfolioTools | ToolDefinition[] | Portfolio monitoring tools |
financialTools | ToolDefinition[] | Withdrawal and transaction tools |
rewardsTools | ToolDefinition[] | Reward claiming tools |
optimizerTools | ToolDefinition[] | Optimization tools |
WalletContextStore | Class | Per-session wallet address storage |
WalletNotConnectedError | Class | Error thrown when no wallet is connected |
formatToolError | Function | Convert any error into an LLM-friendly ToolResult |
textResult | Function | Wrap a string as a success ToolResult |
errorResult | Function | Wrap a string as an error ToolResult |
jsonResult | Function | Wrap data as pretty-printed JSON ToolResult |
formatAddress | Function | Truncate address to 0x1234...abcd form |
DEFAULT_SYSTEM_PROMPT | string | Built-in DeFi assistant system prompt |
Type Exports
import type {
ToolDefinition,
ToolContext,
ToolResult,
ServerConfig,
ResolvedServerConfig,
} from '@gizatech/mcp-server';