# MCP Toolkit Basic Examples

This directory contains basic examples demonstrating how to use the MCP Toolkit.

## Simple Client Example

The `simple-client.ts` example demonstrates how to:

1. Create an MCP client
2. Connect to a server using stdio transport
3. List available tools
4. Call a tool
5. List and read resources
6. Subscribe to resource updates
7. Handle errors and cleanup

## Running the Example

```bash
# Install dependencies
npm install

# Build the toolkit
npm run build

# Run the example
npx tsx examples/basic/simple-client.ts
```

## Key Concepts

### Client Creation

```typescript
// Create a client with optional client info and configuration
const client = new McpClient(
  {
    name: 'example-client',
    version: '1.0.0'
  },
  {
    capabilities: {
      resources: {},
      tools: {},
      prompts: {}
    },
    requestTimeout: 10000
  }
);
```

### Server Connection

```typescript
// Create a transport
const transport = new StdioClientTransport({
  command: 'node',
  args: ['path/to/server.js'],
  inherit: false
});

// Connect to the server
await client.connect(transport);
```

### Tool Discovery and Execution

```typescript
// List available tools
const tools = await client.listTools();

// Call a tool
const result = await client.callTool('tool-name', { 
  param1: 'value1', 
  param2: 'value2' 
});
```

### Resource Management

```typescript
// List available resources
const resources = await client.listResources();

// Read a resource
const content = await client.readResource('mcp://server-name/resource-path');

// Subscribe to resource updates
await client.subscribeResource('mcp://server-name/resource-path');
client.onResourceUpdated((event) => {
  console.log('Resource updated:', event);
});
```

### Cleanup

```typescript
// Close the connection when done
await client.close();
```