Skip to main content

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 });

Cherry-Picking Tools

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:
ImportTools Included
walletToolsconnect_wallet, disconnect_wallet
accountToolscreate_smart_account, get_smart_account
protocolToolsget_protocols, get_tokens, get_stats, get_tvl
lifecycleToolsactivate_agent, deactivate_agent, top_up, run_agent
portfolioToolsget_portfolio, get_performance, get_apr, get_deposits
financialToolswithdraw, get_withdrawal_status, get_transactions, get_fees
rewardsToolsclaim_rewards
optimizerToolsoptimize
allToolsAll 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.

Creating Custom Tools

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();

Tool Definition Interface

interface ToolDefinition {
  name: string;
  description: string;
  inputSchema: z.ZodObject<z.ZodRawShape>;
  handler: (ctx: ToolContext, input: Record<string, unknown>) => Promise<ToolResult>;
}
The ToolContext provides:
FieldTypeDescription
gizaGizaSDK instance for making API calls
walletStoreWalletContextStoreSession-based wallet storage
sessionIdstringCurrent 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:
ExportTypeDescription
serveFunctionOne-call convenience: resolve config, create server, connect transport
createGizaServerFunctionCreate a GizaServer from a resolved config
GizaServerClassMCP server wrapping the Giza SDK
resolveConfigFunctionResolve partial config using env vars and defaults
allToolsToolDefinition[]All 23 built-in tools
walletToolsToolDefinition[]Wallet connection tools
accountToolsToolDefinition[]Smart account tools
protocolToolsToolDefinition[]Protocol discovery tools
lifecycleToolsToolDefinition[]Agent lifecycle tools
portfolioToolsToolDefinition[]Portfolio monitoring tools
financialToolsToolDefinition[]Withdrawal and transaction tools
rewardsToolsToolDefinition[]Reward claiming tools
optimizerToolsToolDefinition[]Optimization tools
WalletContextStoreClassPer-session wallet address storage
WalletNotConnectedErrorClassError thrown when no wallet is connected
formatToolErrorFunctionConvert any error into an LLM-friendly ToolResult
textResultFunctionWrap a string as a success ToolResult
errorResultFunctionWrap a string as an error ToolResult
jsonResultFunctionWrap data as pretty-printed JSON ToolResult
formatAddressFunctionTruncate address to 0x1234...abcd form
DEFAULT_SYSTEM_PROMPTstringBuilt-in DeFi assistant system prompt

Type Exports

import type {
  ToolDefinition,
  ToolContext,
  ToolResult,
  ServerConfig,
  ResolvedServerConfig,
} from '@gizatech/mcp-server';