This commit is contained in:
Zack Lee 2024-11-20 12:24:08 -05:00
commit ba7d5b866d
No known key found for this signature in database

View file

@ -1,11 +1,11 @@
---
title: "TypeScript Type Definitions"
title: "TypeScript type definitions"
description: "TypeScript type system documentation"
---
## Core Protocol Types
## Core protocol types
### JSON-RPC Types
### JSON-RPC types
```typescript
export const JSONRPC_VERSION = "2.0";
@ -53,7 +53,7 @@ export type JSONRPCMessage =
| JSONRPCError;
```
### Message Content Types
### Message content types
```typescript
/** Text provided to or from an LLM */
@ -84,7 +84,7 @@ export interface Progress {
export type ProgressCallback = (progress: Progress) => void;
```
### Resource Types
### Resource types
```typescript
/** The contents of a specific resource */
@ -120,7 +120,7 @@ export interface ResourceTemplate {
}
```
### Tool Types
### Tool types
```typescript
/** Definition for a tool the client can call */
@ -134,7 +134,7 @@ export interface Tool {
}
```
### Prompt Types
### Prompt types
```typescript
/** Describes an argument that a prompt can accept */
@ -152,9 +152,9 @@ export interface Prompt {
}
```
## Request/Response Types
## Request/response types
### Resource Requests
### Resource requests
```typescript
export interface ListResourcesRequest {
@ -195,7 +195,7 @@ export interface UnsubscribeRequest {
}
```
### Tool Requests
### Tool requests
```typescript
export interface ListToolsRequest {
@ -226,7 +226,7 @@ export interface CallToolResult {
}
```
### Prompt Requests
### Prompt requests
```typescript
export interface ListPromptsRequest {
@ -255,9 +255,9 @@ export interface GetPromptResult {
}
```
## Protocol Types
## Protocol types
### Implementation Info
### Implementation info
```typescript
export interface Implementation {
@ -266,7 +266,7 @@ export interface Implementation {
}
```
### Capability Types
### Capability types
```typescript
export interface ResourceCapabilities {
@ -296,7 +296,7 @@ export interface ClientCapabilities {
}
```
### Notification Types
### Notification types
```typescript
export interface ResourceUpdatedNotification {
@ -328,7 +328,7 @@ export type ServerNotification =
| LogMessageNotification;
```
## Error Types
## Error types
```typescript
export enum ErrorCode {
@ -354,7 +354,7 @@ export class McpError extends Error {
}
```
## Transport Types
## Transport types
```typescript
export interface Transport {
@ -373,9 +373,9 @@ export interface StdioServerParameters {
}
```
## Usage Examples
## Usage examples
### Type Guards
### Type guards
```typescript
function isTextContent(content:
@ -391,7 +391,7 @@ function isResourceUpdatedNotification(
}
```
### Type Assertions
### Type assertions
```typescript
function assertResource(data: unknown): asserts data is Resource {
@ -409,7 +409,7 @@ function assertResource(data: unknown): asserts data is Resource {
}
```
### Using Generics
### Using generics
```typescript
async function handleResourceContent<T extends ResourceContents>(
@ -425,7 +425,7 @@ async function handleResourceContent<T extends ResourceContents>(
}
```
### Working with Union Types
### Working with union types
```typescript
function processMessage(message: SamplingMessage): string {
@ -442,7 +442,7 @@ function processMessage(message: SamplingMessage): string {
}
```
## Type Utilities
## Type utilities
```typescript
/** Helper type to extract request params from method name */