Spaces:
Running
Running
Merge pull request #918 from jlowin/fields
Browse files- docs/.cursor/rules/mintlify.mdc +364 -0
- docs/clients/logging.mdx +22 -9
- docs/clients/progress.mdx +21 -10
- docs/clients/sampling.mdx +83 -22
- docs/servers/auth/bearer.mdx +67 -22
- docs/servers/prompts.mdx +35 -22
- docs/servers/resources.mdx +36 -17
- docs/servers/server.mdx +53 -7
- docs/servers/tools.mdx +61 -24
docs/.cursor/rules/mintlify.mdc
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
description:
|
| 3 |
+
globs: *.mdx
|
| 4 |
+
alwaysApply: false
|
| 5 |
+
---
|
| 6 |
+
# Mintlify technical writing assistant
|
| 7 |
+
|
| 8 |
+
You are an AI writing assistant specialized in creating exceptional technical documentation using Mintlify components and following industry-leading technical writing practices.
|
| 9 |
+
|
| 10 |
+
## Core writing principles
|
| 11 |
+
|
| 12 |
+
### Language and style requirements
|
| 13 |
+
- Use clear, direct language appropriate for technical audiences
|
| 14 |
+
- Write in second person ("you") for instructions and procedures
|
| 15 |
+
- Use active voice over passive voice
|
| 16 |
+
- Employ present tense for current states, future tense for outcomes
|
| 17 |
+
- Maintain consistent terminology throughout all documentation
|
| 18 |
+
- Keep sentences concise while providing necessary context
|
| 19 |
+
- Use parallel structure in lists, headings, and procedures
|
| 20 |
+
|
| 21 |
+
### Content organization standards
|
| 22 |
+
- Lead with the most important information (inverted pyramid structure)
|
| 23 |
+
- Use progressive disclosure: basic concepts before advanced ones
|
| 24 |
+
- Break complex procedures into numbered steps
|
| 25 |
+
- Include prerequisites and context before instructions
|
| 26 |
+
- Provide expected outcomes for each major step
|
| 27 |
+
- End sections with next steps or related information
|
| 28 |
+
- Use descriptive, keyword-rich headings for navigation and SEO
|
| 29 |
+
|
| 30 |
+
### User-centered approach
|
| 31 |
+
- Focus on user goals and outcomes rather than system features
|
| 32 |
+
- Anticipate common questions and address them proactively
|
| 33 |
+
- Include troubleshooting for likely failure points
|
| 34 |
+
- Provide multiple pathways when appropriate (beginner vs advanced), but offer an opinionated path for people to follow to avoid overwhelming with options
|
| 35 |
+
|
| 36 |
+
## Mintlify component reference
|
| 37 |
+
|
| 38 |
+
### Callout components
|
| 39 |
+
|
| 40 |
+
#### Note - Additional helpful information
|
| 41 |
+
|
| 42 |
+
<Note>
|
| 43 |
+
Supplementary information that supports the main content without interrupting flow
|
| 44 |
+
</Note>
|
| 45 |
+
|
| 46 |
+
#### Tip - Best practices and pro tips
|
| 47 |
+
|
| 48 |
+
<Tip>
|
| 49 |
+
Expert advice, shortcuts, or best practices that enhance user success
|
| 50 |
+
</Tip>
|
| 51 |
+
|
| 52 |
+
#### Warning - Important cautions
|
| 53 |
+
|
| 54 |
+
<Warning>
|
| 55 |
+
Critical information about potential issues, breaking changes, or destructive actions
|
| 56 |
+
</Warning>
|
| 57 |
+
|
| 58 |
+
#### Info - Neutral contextual information
|
| 59 |
+
|
| 60 |
+
<Info>
|
| 61 |
+
Background information, context, or neutral announcements
|
| 62 |
+
</Info>
|
| 63 |
+
|
| 64 |
+
#### Check - Success confirmations
|
| 65 |
+
|
| 66 |
+
<Check>
|
| 67 |
+
Positive confirmations, successful completions, or achievement indicators
|
| 68 |
+
</Check>
|
| 69 |
+
|
| 70 |
+
### Code components
|
| 71 |
+
|
| 72 |
+
#### Single code block
|
| 73 |
+
|
| 74 |
+
```javascript config.js
|
| 75 |
+
const apiConfig = {
|
| 76 |
+
baseURL: 'https://api.example.com',
|
| 77 |
+
timeout: 5000,
|
| 78 |
+
headers: {
|
| 79 |
+
'Authorization': `Bearer ${process.env.API_TOKEN}`
|
| 80 |
+
}
|
| 81 |
+
};
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
#### Code group with multiple languages
|
| 85 |
+
|
| 86 |
+
<CodeGroup>
|
| 87 |
+
```javascript Node.js
|
| 88 |
+
const response = await fetch('/api/endpoint', {
|
| 89 |
+
headers: { Authorization: `Bearer ${apiKey}` }
|
| 90 |
+
});
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
```python Python
|
| 94 |
+
import requests
|
| 95 |
+
response = requests.get('/api/endpoint',
|
| 96 |
+
headers={'Authorization': f'Bearer {api_key}'})
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
```curl cURL
|
| 100 |
+
curl -X GET '/api/endpoint' \
|
| 101 |
+
-H 'Authorization: Bearer YOUR_API_KEY'
|
| 102 |
+
```
|
| 103 |
+
</CodeGroup>
|
| 104 |
+
|
| 105 |
+
#### Request/Response examples
|
| 106 |
+
|
| 107 |
+
<RequestExample>
|
| 108 |
+
```bash cURL
|
| 109 |
+
curl -X POST 'https://api.example.com/users' \
|
| 110 |
+
-H 'Content-Type: application/json' \
|
| 111 |
+
-d '{"name": "John Doe", "email": "john@example.com"}'
|
| 112 |
+
```
|
| 113 |
+
</RequestExample>
|
| 114 |
+
|
| 115 |
+
<ResponseExample>
|
| 116 |
+
```json Success
|
| 117 |
+
{
|
| 118 |
+
"id": "user_123",
|
| 119 |
+
"name": "John Doe",
|
| 120 |
+
"email": "john@example.com",
|
| 121 |
+
"created_at": "2024-01-15T10:30:00Z"
|
| 122 |
+
}
|
| 123 |
+
```
|
| 124 |
+
</ResponseExample>
|
| 125 |
+
|
| 126 |
+
### Structural components
|
| 127 |
+
|
| 128 |
+
#### Steps for procedures
|
| 129 |
+
|
| 130 |
+
<Steps>
|
| 131 |
+
<Step title="Install dependencies">
|
| 132 |
+
Run `npm install` to install required packages.
|
| 133 |
+
|
| 134 |
+
<Check>
|
| 135 |
+
Verify installation by running `npm list`.
|
| 136 |
+
</Check>
|
| 137 |
+
</Step>
|
| 138 |
+
|
| 139 |
+
<Step title="Configure environment">
|
| 140 |
+
Create a `.env` file with your API credentials.
|
| 141 |
+
|
| 142 |
+
```bash
|
| 143 |
+
API_KEY=your_api_key_here
|
| 144 |
+
```
|
| 145 |
+
|
| 146 |
+
<Warning>
|
| 147 |
+
Never commit API keys to version control.
|
| 148 |
+
</Warning>
|
| 149 |
+
</Step>
|
| 150 |
+
</Steps>
|
| 151 |
+
|
| 152 |
+
#### Tabs for alternative content
|
| 153 |
+
|
| 154 |
+
<Tabs>
|
| 155 |
+
<Tab title="macOS">
|
| 156 |
+
```bash
|
| 157 |
+
brew install node
|
| 158 |
+
npm install -g package-name
|
| 159 |
+
```
|
| 160 |
+
</Tab>
|
| 161 |
+
|
| 162 |
+
<Tab title="Windows">
|
| 163 |
+
```powershell
|
| 164 |
+
choco install nodejs
|
| 165 |
+
npm install -g package-name
|
| 166 |
+
```
|
| 167 |
+
</Tab>
|
| 168 |
+
|
| 169 |
+
<Tab title="Linux">
|
| 170 |
+
```bash
|
| 171 |
+
sudo apt install nodejs npm
|
| 172 |
+
npm install -g package-name
|
| 173 |
+
```
|
| 174 |
+
</Tab>
|
| 175 |
+
</Tabs>
|
| 176 |
+
|
| 177 |
+
#### Accordions for collapsible content
|
| 178 |
+
|
| 179 |
+
<AccordionGroup>
|
| 180 |
+
<Accordion title="Troubleshooting connection issues">
|
| 181 |
+
- **Firewall blocking**: Ensure ports 80 and 443 are open
|
| 182 |
+
- **Proxy configuration**: Set HTTP_PROXY environment variable
|
| 183 |
+
- **DNS resolution**: Try using 8.8.8.8 as DNS server
|
| 184 |
+
</Accordion>
|
| 185 |
+
|
| 186 |
+
<Accordion title="Advanced configuration">
|
| 187 |
+
```javascript
|
| 188 |
+
const config = {
|
| 189 |
+
performance: { cache: true, timeout: 30000 },
|
| 190 |
+
security: { encryption: 'AES-256' }
|
| 191 |
+
};
|
| 192 |
+
```
|
| 193 |
+
</Accordion>
|
| 194 |
+
</AccordionGroup>
|
| 195 |
+
|
| 196 |
+
### API documentation components
|
| 197 |
+
|
| 198 |
+
#### Parameter fields
|
| 199 |
+
|
| 200 |
+
<ParamField path="user_id" type="string" required>
|
| 201 |
+
Unique identifier for the user. Must be a valid UUID v4 format.
|
| 202 |
+
</ParamField>
|
| 203 |
+
|
| 204 |
+
<ParamField body="email" type="string" required>
|
| 205 |
+
User's email address. Must be valid and unique within the system.
|
| 206 |
+
</ParamField>
|
| 207 |
+
|
| 208 |
+
<ParamField query="limit" type="integer" default="10">
|
| 209 |
+
Maximum number of results to return. Range: 1-100.
|
| 210 |
+
</ParamField>
|
| 211 |
+
|
| 212 |
+
<ParamField header="Authorization" type="string" required>
|
| 213 |
+
Bearer token for API authentication. Format: `Bearer YOUR_API_KEY`
|
| 214 |
+
</ParamField>
|
| 215 |
+
|
| 216 |
+
#### Response fields
|
| 217 |
+
|
| 218 |
+
<ResponseField name="user_id" type="string" required>
|
| 219 |
+
Unique identifier assigned to the newly created user.
|
| 220 |
+
</ResponseField>
|
| 221 |
+
|
| 222 |
+
<ResponseField name="created_at" type="timestamp">
|
| 223 |
+
ISO 8601 formatted timestamp of when the user was created.
|
| 224 |
+
</ResponseField>
|
| 225 |
+
|
| 226 |
+
<ResponseField name="permissions" type="array">
|
| 227 |
+
List of permission strings assigned to this user.
|
| 228 |
+
</ResponseField>
|
| 229 |
+
|
| 230 |
+
#### Expandable nested fields
|
| 231 |
+
|
| 232 |
+
<ResponseField name="user" type="object">
|
| 233 |
+
Complete user object with all associated data.
|
| 234 |
+
|
| 235 |
+
<Expandable title="User properties">
|
| 236 |
+
<ResponseField name="profile" type="object">
|
| 237 |
+
User profile information including personal details.
|
| 238 |
+
|
| 239 |
+
<Expandable title="Profile details">
|
| 240 |
+
<ResponseField name="first_name" type="string">
|
| 241 |
+
User's first name as entered during registration.
|
| 242 |
+
</ResponseField>
|
| 243 |
+
|
| 244 |
+
<ResponseField name="avatar_url" type="string | null">
|
| 245 |
+
URL to user's profile picture. Returns null if no avatar is set.
|
| 246 |
+
</ResponseField>
|
| 247 |
+
</Expandable>
|
| 248 |
+
</ResponseField>
|
| 249 |
+
</Expandable>
|
| 250 |
+
</ResponseField>
|
| 251 |
+
|
| 252 |
+
### Interactive components
|
| 253 |
+
|
| 254 |
+
#### Cards for navigation
|
| 255 |
+
|
| 256 |
+
<Card title="Getting started guide" icon="rocket" href="/quickstart">
|
| 257 |
+
Complete walkthrough from installation to your first API call in under 10 minutes.
|
| 258 |
+
</Card>
|
| 259 |
+
|
| 260 |
+
<CardGroup cols={2}>
|
| 261 |
+
<Card title="Authentication" icon="key" href="/auth">
|
| 262 |
+
Learn how to authenticate requests using API keys or JWT tokens.
|
| 263 |
+
</Card>
|
| 264 |
+
|
| 265 |
+
<Card title="Rate limiting" icon="clock" href="/rate-limits">
|
| 266 |
+
Understand rate limits and best practices for high-volume usage.
|
| 267 |
+
</Card>
|
| 268 |
+
</CardGroup>
|
| 269 |
+
|
| 270 |
+
### Media and advanced components
|
| 271 |
+
|
| 272 |
+
#### Frames for images
|
| 273 |
+
|
| 274 |
+
Wrap all images in frames.
|
| 275 |
+
|
| 276 |
+
<Frame>
|
| 277 |
+
<img src="/images/dashboard.png" alt="Main dashboard showing analytics overview" />
|
| 278 |
+
</Frame>
|
| 279 |
+
|
| 280 |
+
<Frame caption="The analytics dashboard provides real-time insights">
|
| 281 |
+
<img src="/images/analytics.png" alt="Analytics dashboard with charts" />
|
| 282 |
+
</Frame>
|
| 283 |
+
|
| 284 |
+
#### Tooltips and updates
|
| 285 |
+
|
| 286 |
+
<Tooltip tip="Application Programming Interface - protocols for building software">
|
| 287 |
+
API
|
| 288 |
+
</Tooltip>
|
| 289 |
+
|
| 290 |
+
<Update label="Version 2.1.0" description="Released March 15, 2024">
|
| 291 |
+
## New features
|
| 292 |
+
- Added bulk user import functionality
|
| 293 |
+
- Improved error messages with actionable suggestions
|
| 294 |
+
|
| 295 |
+
## Bug fixes
|
| 296 |
+
- Fixed pagination issue with large datasets
|
| 297 |
+
- Resolved authentication timeout problems
|
| 298 |
+
</Update>
|
| 299 |
+
|
| 300 |
+
## Required page structure
|
| 301 |
+
|
| 302 |
+
Every documentation page must begin with YAML frontmatter:
|
| 303 |
+
|
| 304 |
+
```yaml
|
| 305 |
+
---
|
| 306 |
+
title: "Clear, specific, keyword-rich title"
|
| 307 |
+
description: "Concise description explaining page purpose and value"
|
| 308 |
+
---
|
| 309 |
+
```
|
| 310 |
+
|
| 311 |
+
## Content quality standards
|
| 312 |
+
|
| 313 |
+
### Code examples requirements
|
| 314 |
+
- Always include complete, runnable examples that users can copy and execute
|
| 315 |
+
- Show proper error handling and edge case management
|
| 316 |
+
- Use realistic data instead of placeholder values
|
| 317 |
+
- Include expected outputs and results for verification
|
| 318 |
+
- Test all code examples thoroughly before publishing
|
| 319 |
+
- Specify language and include filename when relevant
|
| 320 |
+
- Add explanatory comments for complex logic
|
| 321 |
+
|
| 322 |
+
### API documentation requirements
|
| 323 |
+
- Document all parameters including optional ones with clear descriptions
|
| 324 |
+
- Show both success and error response examples with realistic data
|
| 325 |
+
- Include rate limiting information with specific limits
|
| 326 |
+
- Provide authentication examples showing proper format
|
| 327 |
+
- Explain all HTTP status codes and error handling
|
| 328 |
+
- Cover complete request/response cycles
|
| 329 |
+
|
| 330 |
+
### Accessibility requirements
|
| 331 |
+
- Include descriptive alt text for all images and diagrams
|
| 332 |
+
- Use specific, actionable link text instead of "click here"
|
| 333 |
+
- Ensure proper heading hierarchy starting with H2
|
| 334 |
+
- Provide keyboard navigation considerations
|
| 335 |
+
- Use sufficient color contrast in examples and visuals
|
| 336 |
+
- Structure content for easy scanning with headers and lists
|
| 337 |
+
|
| 338 |
+
## AI assistant instructions
|
| 339 |
+
|
| 340 |
+
### Component selection logic
|
| 341 |
+
- Use **Steps** for procedures, tutorials, setup guides, and sequential instructions
|
| 342 |
+
- Use **Tabs** for platform-specific content or alternative approaches
|
| 343 |
+
- Use **CodeGroup** when showing the same concept in multiple languages
|
| 344 |
+
- Use **Accordions** for supplementary information that might interrupt flow
|
| 345 |
+
- Use **Cards and CardGroup** for navigation, feature overviews, and related resources
|
| 346 |
+
- Use **RequestExample/ResponseExample** specifically for API endpoint documentation
|
| 347 |
+
- Use **ParamField** for API parameters, **ResponseField** for API responses
|
| 348 |
+
- Use **Expandable** for nested object properties or hierarchical information
|
| 349 |
+
|
| 350 |
+
### Quality assurance checklist
|
| 351 |
+
- Verify all code examples are syntactically correct and executable
|
| 352 |
+
- Test all links to ensure they are functional and lead to relevant content
|
| 353 |
+
- Validate Mintlify component syntax with all required properties
|
| 354 |
+
- Confirm proper heading hierarchy with H2 for main sections, H3 for subsections
|
| 355 |
+
- Ensure content flows logically from basic concepts to advanced topics
|
| 356 |
+
- Check for consistency in terminology, formatting, and component usage
|
| 357 |
+
|
| 358 |
+
### Error prevention strategies
|
| 359 |
+
- Always include realistic error handling in code examples
|
| 360 |
+
- Provide dedicated troubleshooting sections for complex procedures
|
| 361 |
+
- Explain prerequisites clearly before beginning instructions
|
| 362 |
+
- Include verification and testing steps with expected outcomes
|
| 363 |
+
- Add appropriate warnings for destructive or security-sensitive actions
|
| 364 |
+
- Validate all technical information through testing before publication
|
docs/clients/logging.mdx
CHANGED
|
@@ -11,7 +11,7 @@ import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
| 11 |
|
| 12 |
MCP servers can emit log messages to clients. The client can handle these logs through a log handler callback.
|
| 13 |
|
| 14 |
-
##
|
| 15 |
|
| 16 |
Provide a `log_handler` function when creating the client:
|
| 17 |
|
|
@@ -31,13 +31,27 @@ client = Client(
|
|
| 31 |
)
|
| 32 |
```
|
| 33 |
|
| 34 |
-
##
|
| 35 |
|
| 36 |
-
The `log_handler` receives a `LogMessage` object
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
```python
|
| 43 |
async def detailed_log_handler(message: LogMessage):
|
|
@@ -51,13 +65,12 @@ async def detailed_log_handler(message: LogMessage):
|
|
| 51 |
|
| 52 |
## Default Log Handling
|
| 53 |
|
| 54 |
-
If you don't provide a custom `log_handler`, FastMCP uses a default handler that emits
|
| 55 |
|
| 56 |
```python
|
| 57 |
-
# Without custom handler - uses default DEBUG logging
|
| 58 |
client = Client("my_mcp_server.py")
|
| 59 |
|
| 60 |
async with client:
|
| 61 |
-
# Server logs will be emitted at DEBUG level
|
| 62 |
await client.call_tool("some_tool")
|
| 63 |
```
|
|
|
|
| 11 |
|
| 12 |
MCP servers can emit log messages to clients. The client can handle these logs through a log handler callback.
|
| 13 |
|
| 14 |
+
## Log Handler
|
| 15 |
|
| 16 |
Provide a `log_handler` function when creating the client:
|
| 17 |
|
|
|
|
| 31 |
)
|
| 32 |
```
|
| 33 |
|
| 34 |
+
### Handler Parameters
|
| 35 |
|
| 36 |
+
The `log_handler` is called every time a log message is received. It receives a `LogMessage` object:
|
| 37 |
|
| 38 |
+
<Card icon="code" title="Log Handler Parameters">
|
| 39 |
+
<ResponseField name="LogMessage" type="Log Message Object">
|
| 40 |
+
<Expandable title="attributes">
|
| 41 |
+
<ResponseField name="level" type='Literal["debug", "info", "notice", "warning", "error", "critical", "alert", "emergency"]'>
|
| 42 |
+
The log level
|
| 43 |
+
</ResponseField>
|
| 44 |
+
|
| 45 |
+
<ResponseField name="logger" type="str | None">
|
| 46 |
+
The logger name (optional, may be None)
|
| 47 |
+
</ResponseField>
|
| 48 |
+
|
| 49 |
+
<ResponseField name="data" type="Any">
|
| 50 |
+
The actual log message content
|
| 51 |
+
</ResponseField>
|
| 52 |
+
</Expandable>
|
| 53 |
+
</ResponseField>
|
| 54 |
+
</Card>
|
| 55 |
|
| 56 |
```python
|
| 57 |
async def detailed_log_handler(message: LogMessage):
|
|
|
|
| 65 |
|
| 66 |
## Default Log Handling
|
| 67 |
|
| 68 |
+
If you don't provide a custom `log_handler`, FastMCP uses a default handler that emits a DEBUG-level FastMCP log for every log message received from the server, which is useful for visibility without polluting your own logs.
|
| 69 |
|
| 70 |
```python
|
|
|
|
| 71 |
client = Client("my_mcp_server.py")
|
| 72 |
|
| 73 |
async with client:
|
| 74 |
+
# Server logs will be emitted at DEBUG level automatically
|
| 75 |
await client.call_tool("some_tool")
|
| 76 |
```
|
docs/clients/progress.mdx
CHANGED
|
@@ -11,7 +11,7 @@ import { VersionBadge } from '/snippets/version-badge.mdx'
|
|
| 11 |
|
| 12 |
MCP servers can report progress during long-running operations. The client can receive these updates through a progress handler.
|
| 13 |
|
| 14 |
-
##
|
| 15 |
|
| 16 |
Set a progress handler when creating the client:
|
| 17 |
|
|
@@ -35,6 +35,26 @@ client = Client(
|
|
| 35 |
)
|
| 36 |
```
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
## Per-Call Progress Handler
|
| 39 |
|
| 40 |
Override the progress handler for specific tool calls:
|
|
@@ -48,12 +68,3 @@ async with client:
|
|
| 48 |
progress_handler=my_progress_handler
|
| 49 |
)
|
| 50 |
```
|
| 51 |
-
|
| 52 |
-
## Handler Parameters
|
| 53 |
-
|
| 54 |
-
The progress handler receives:
|
| 55 |
-
|
| 56 |
-
- **`progress`** (float): Current progress value
|
| 57 |
-
- **`total`** (float | None): Expected total value (may be None)
|
| 58 |
-
- **`message`** (str | None): Optional status message (may be None)
|
| 59 |
-
|
|
|
|
| 11 |
|
| 12 |
MCP servers can report progress during long-running operations. The client can receive these updates through a progress handler.
|
| 13 |
|
| 14 |
+
## Progress Handler
|
| 15 |
|
| 16 |
Set a progress handler when creating the client:
|
| 17 |
|
|
|
|
| 35 |
)
|
| 36 |
```
|
| 37 |
|
| 38 |
+
### Handler Parameters
|
| 39 |
+
|
| 40 |
+
The progress handler receives three parameters:
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
<Card icon="code" title="Progress Handler Parameters">
|
| 44 |
+
<ResponseField name="progress" type="float">
|
| 45 |
+
Current progress value
|
| 46 |
+
</ResponseField>
|
| 47 |
+
|
| 48 |
+
<ResponseField name="total" type="float | None">
|
| 49 |
+
Expected total value (may be None)
|
| 50 |
+
</ResponseField>
|
| 51 |
+
|
| 52 |
+
<ResponseField name="message" type="str | None">
|
| 53 |
+
Optional status message (may be None)
|
| 54 |
+
</ResponseField>
|
| 55 |
+
</Card>
|
| 56 |
+
|
| 57 |
+
|
| 58 |
## Per-Call Progress Handler
|
| 59 |
|
| 60 |
Override the progress handler for specific tool calls:
|
|
|
|
| 68 |
progress_handler=my_progress_handler
|
| 69 |
)
|
| 70 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
docs/clients/sampling.mdx
CHANGED
|
@@ -5,13 +5,13 @@ description: Handle server-initiated LLM sampling requests.
|
|
| 5 |
icon: robot
|
| 6 |
---
|
| 7 |
|
| 8 |
-
import { VersionBadge } from
|
| 9 |
|
| 10 |
<VersionBadge version="2.0.0" />
|
| 11 |
|
| 12 |
MCP servers can request LLM completions from clients. The client handles these requests through a sampling handler callback.
|
| 13 |
|
| 14 |
-
##
|
| 15 |
|
| 16 |
Provide a `sampling_handler` function when creating the client:
|
| 17 |
|
|
@@ -38,26 +38,88 @@ client = Client(
|
|
| 38 |
)
|
| 39 |
```
|
| 40 |
|
| 41 |
-
## Handler Parameters
|
| 42 |
|
| 43 |
The sampling handler receives three parameters:
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
## Basic Example
|
| 63 |
|
|
@@ -75,10 +137,10 @@ async def basic_sampling_handler(
|
|
| 75 |
for message in messages:
|
| 76 |
content = message.content.text if hasattr(message.content, 'text') else str(message.content)
|
| 77 |
conversation.append(f"{message.role}: {content}")
|
| 78 |
-
|
| 79 |
# Use the system prompt if provided
|
| 80 |
system_prompt = params.systemPrompt or "You are a helpful assistant."
|
| 81 |
-
|
| 82 |
# Here you would integrate with your preferred LLM service
|
| 83 |
# This is just a placeholder response
|
| 84 |
return f"Response based on conversation: {' | '.join(conversation)}"
|
|
@@ -88,4 +150,3 @@ client = Client(
|
|
| 88 |
sampling_handler=basic_sampling_handler
|
| 89 |
)
|
| 90 |
```
|
| 91 |
-
|
|
|
|
| 5 |
icon: robot
|
| 6 |
---
|
| 7 |
|
| 8 |
+
import { VersionBadge } from "/snippets/version-badge.mdx";
|
| 9 |
|
| 10 |
<VersionBadge version="2.0.0" />
|
| 11 |
|
| 12 |
MCP servers can request LLM completions from clients. The client handles these requests through a sampling handler callback.
|
| 13 |
|
| 14 |
+
## Sampling Handler
|
| 15 |
|
| 16 |
Provide a `sampling_handler` function when creating the client:
|
| 17 |
|
|
|
|
| 38 |
)
|
| 39 |
```
|
| 40 |
|
| 41 |
+
### Handler Parameters
|
| 42 |
|
| 43 |
The sampling handler receives three parameters:
|
| 44 |
|
| 45 |
+
<Card icon="code" title="Sampling Handler Parameters">
|
| 46 |
+
<ResponseField name="SamplingMessage" type="Sampling Message Object">
|
| 47 |
+
<Expandable title="attributes">
|
| 48 |
+
<ResponseField name="role" type='Literal["user", "assistant"]'>
|
| 49 |
+
The role of the message.
|
| 50 |
+
</ResponseField>
|
| 51 |
+
|
| 52 |
+
<ResponseField name="content" type="TextContent | ImageContent | AudioContent">
|
| 53 |
+
The content of the message.
|
| 54 |
+
|
| 55 |
+
TextContent is most common, and has a `.text` attribute.
|
| 56 |
+
</ResponseField>
|
| 57 |
+
|
| 58 |
+
</Expandable>
|
| 59 |
+
</ResponseField>
|
| 60 |
+
<ResponseField name="SamplingParams" type="Sampling Parameters Object">
|
| 61 |
+
<Expandable title="attributes">
|
| 62 |
+
<ResponseField name="messages" type="list[SamplingMessage]">
|
| 63 |
+
The messages to sample from
|
| 64 |
+
</ResponseField>
|
| 65 |
+
|
| 66 |
+
<ResponseField name="modelPreferences" type="ModelPreferences | None">
|
| 67 |
+
The server's preferences for which model to select. The client MAY ignore
|
| 68 |
+
these preferences.
|
| 69 |
+
<Expandable title="attributes">
|
| 70 |
+
<ResponseField name="hints" type="list[ModelHint] | None">
|
| 71 |
+
The hints to use for model selection.
|
| 72 |
+
</ResponseField>
|
| 73 |
+
|
| 74 |
+
<ResponseField name="costPriority" type="float | None">
|
| 75 |
+
The cost priority for model selection.
|
| 76 |
+
</ResponseField>
|
| 77 |
+
|
| 78 |
+
<ResponseField name="speedPriority" type="float | None">
|
| 79 |
+
The speed priority for model selection.
|
| 80 |
+
</ResponseField>
|
| 81 |
+
|
| 82 |
+
<ResponseField name="intelligencePriority" type="float | None">
|
| 83 |
+
The intelligence priority for model selection.
|
| 84 |
+
</ResponseField>
|
| 85 |
+
</Expandable>
|
| 86 |
+
</ResponseField>
|
| 87 |
+
|
| 88 |
+
<ResponseField name="systemPrompt" type="str | None">
|
| 89 |
+
An optional system prompt the server wants to use for sampling.
|
| 90 |
+
</ResponseField>
|
| 91 |
+
|
| 92 |
+
<ResponseField name="includeContext" type="IncludeContext | None">
|
| 93 |
+
A request to include context from one or more MCP servers (including the caller), to
|
| 94 |
+
be attached to the prompt.
|
| 95 |
+
</ResponseField>
|
| 96 |
+
|
| 97 |
+
<ResponseField name="temperature" type="float | None">
|
| 98 |
+
The sampling temperature.
|
| 99 |
+
</ResponseField>
|
| 100 |
+
|
| 101 |
+
<ResponseField name="maxTokens" type="int">
|
| 102 |
+
The maximum number of tokens to sample.
|
| 103 |
+
</ResponseField>
|
| 104 |
+
|
| 105 |
+
<ResponseField name="stopSequences" type="list[str] | None">
|
| 106 |
+
The stop sequences to use for sampling.
|
| 107 |
+
</ResponseField>
|
| 108 |
+
|
| 109 |
+
<ResponseField name="metadata" type="dict[str, Any] | None">
|
| 110 |
+
Optional metadata to pass through to the LLM provider.
|
| 111 |
+
</ResponseField>
|
| 112 |
+
</Expandable>
|
| 113 |
+
|
| 114 |
+
</ResponseField>
|
| 115 |
+
<ResponseField name="RequestContext" type="Request Context Object">
|
| 116 |
+
<Expandable title="attributes">
|
| 117 |
+
<ResponseField name="request_id" type="RequestId">
|
| 118 |
+
Unique identifier for the MCP request
|
| 119 |
+
</ResponseField>
|
| 120 |
+
</Expandable>
|
| 121 |
+
</ResponseField>
|
| 122 |
+
</Card>
|
| 123 |
|
| 124 |
## Basic Example
|
| 125 |
|
|
|
|
| 137 |
for message in messages:
|
| 138 |
content = message.content.text if hasattr(message.content, 'text') else str(message.content)
|
| 139 |
conversation.append(f"{message.role}: {content}")
|
| 140 |
+
|
| 141 |
# Use the system prompt if provided
|
| 142 |
system_prompt = params.systemPrompt or "You are a helpful assistant."
|
| 143 |
+
|
| 144 |
# Here you would integrate with your preferred LLM service
|
| 145 |
# This is just a placeholder response
|
| 146 |
return f"Response based on conversation: {' | '.join(conversation)}"
|
|
|
|
| 150 |
sampling_handler=basic_sampling_handler
|
| 151 |
)
|
| 152 |
```
|
|
|
docs/servers/auth/bearer.mdx
CHANGED
|
@@ -61,13 +61,27 @@ mcp = FastMCP(name="My MCP Server", auth=auth)
|
|
| 61 |
|
| 62 |
### Configuration Parameters
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
#### Public Key
|
| 73 |
|
|
@@ -141,15 +155,35 @@ print(f"Test token: {token}")
|
|
| 141 |
|
| 142 |
The `create_token()` method accepts these parameters:
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
|
| 155 |
## Accessing Token Claims
|
|
@@ -179,10 +213,21 @@ async def get_my_data(ctx: Context) -> dict:
|
|
| 179 |
|
| 180 |
### AccessToken Properties
|
| 181 |
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
|
|
|
| 61 |
|
| 62 |
### Configuration Parameters
|
| 63 |
|
| 64 |
+
<Card icon="code" title="BearerAuthProvider Configuration">
|
| 65 |
+
<ParamField body="public_key" type="str">
|
| 66 |
+
RSA public key in PEM format for static key validation. Required if `jwks_uri` is not provided
|
| 67 |
+
</ParamField>
|
| 68 |
+
|
| 69 |
+
<ParamField body="jwks_uri" type="str">
|
| 70 |
+
URL for JSON Web Key Set endpoint. Required if `public_key` is not provided
|
| 71 |
+
</ParamField>
|
| 72 |
+
|
| 73 |
+
<ParamField body="issuer" type="str | None">
|
| 74 |
+
Expected JWT `iss` claim value
|
| 75 |
+
</ParamField>
|
| 76 |
+
|
| 77 |
+
<ParamField body="audience" type="str | None">
|
| 78 |
+
Expected JWT `aud` claim value
|
| 79 |
+
</ParamField>
|
| 80 |
+
|
| 81 |
+
<ParamField body="required_scopes" type="list[str] | None">
|
| 82 |
+
Global scopes required for all requests
|
| 83 |
+
</ParamField>
|
| 84 |
+
</Card>
|
| 85 |
|
| 86 |
#### Public Key
|
| 87 |
|
|
|
|
| 155 |
|
| 156 |
The `create_token()` method accepts these parameters:
|
| 157 |
|
| 158 |
+
<Card icon="code" title="create_token() Parameters">
|
| 159 |
+
<ParamField body="subject" type="str" default="fastmcp-user">
|
| 160 |
+
JWT subject claim (usually user ID)
|
| 161 |
+
</ParamField>
|
| 162 |
+
|
| 163 |
+
<ParamField body="issuer" type="str" default="https://fastmcp.example.com">
|
| 164 |
+
JWT issuer claim
|
| 165 |
+
</ParamField>
|
| 166 |
+
|
| 167 |
+
<ParamField body="audience" type="str | None">
|
| 168 |
+
JWT audience claim
|
| 169 |
+
</ParamField>
|
| 170 |
+
|
| 171 |
+
<ParamField body="scopes" type="list[str] | None">
|
| 172 |
+
OAuth scopes to include
|
| 173 |
+
</ParamField>
|
| 174 |
+
|
| 175 |
+
<ParamField body="expires_in_seconds" type="int" default="3600">
|
| 176 |
+
Token expiration time in seconds
|
| 177 |
+
</ParamField>
|
| 178 |
+
|
| 179 |
+
<ParamField body="additional_claims" type="dict | None">
|
| 180 |
+
Extra claims to include in the token
|
| 181 |
+
</ParamField>
|
| 182 |
+
|
| 183 |
+
<ParamField body="kid" type="str | None">
|
| 184 |
+
Key ID for JWKS lookup
|
| 185 |
+
</ParamField>
|
| 186 |
+
</Card>
|
| 187 |
|
| 188 |
|
| 189 |
## Accessing Token Claims
|
|
|
|
| 213 |
|
| 214 |
### AccessToken Properties
|
| 215 |
|
| 216 |
+
<Card icon="code" title="AccessToken Properties">
|
| 217 |
+
<ParamField body="token" type="str">
|
| 218 |
+
The raw JWT string
|
| 219 |
+
</ParamField>
|
| 220 |
+
|
| 221 |
+
<ParamField body="client_id" type="str">
|
| 222 |
+
Authenticated principal identifier
|
| 223 |
+
</ParamField>
|
| 224 |
+
|
| 225 |
+
<ParamField body="scopes" type="list[str]">
|
| 226 |
+
Granted scopes
|
| 227 |
+
</ParamField>
|
| 228 |
+
|
| 229 |
+
<ParamField body="expires_at" type="datetime | None">
|
| 230 |
+
Token expiration timestamp
|
| 231 |
+
</ParamField>
|
| 232 |
+
</Card>
|
| 233 |
|
docs/servers/prompts.mdx
CHANGED
|
@@ -57,6 +57,41 @@ def generate_code_request(language: str, task_description: str) -> PromptMessage
|
|
| 57 |
Functions with `*args` or `**kwargs` are not supported as prompts. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn't possible with variable argument lists.
|
| 58 |
</Tip>
|
| 59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
### Argument Types
|
| 61 |
|
| 62 |
<VersionBadge version="2.9.0" />
|
|
@@ -177,28 +212,6 @@ def data_analysis_prompt(
|
|
| 177 |
|
| 178 |
In this example, the client *must* provide `data_uri`. If `analysis_type` or `include_charts` are omitted, their default values will be used.
|
| 179 |
|
| 180 |
-
### Prompt Metadata
|
| 181 |
-
|
| 182 |
-
While FastMCP infers the name and description from your function, you can override these and add tags using arguments to the `@mcp.prompt` decorator:
|
| 183 |
-
|
| 184 |
-
```python
|
| 185 |
-
@mcp.prompt(
|
| 186 |
-
name="analyze_data_request", # Custom prompt name
|
| 187 |
-
description="Creates a request to analyze data with specific parameters", # Custom description
|
| 188 |
-
tags={"analysis", "data"} # Optional categorization tags
|
| 189 |
-
)
|
| 190 |
-
def data_analysis_prompt(
|
| 191 |
-
data_uri: str = Field(description="The URI of the resource containing the data."),
|
| 192 |
-
analysis_type: str = Field(default="summary", description="Type of analysis.")
|
| 193 |
-
) -> str:
|
| 194 |
-
"""This docstring is ignored when description is provided."""
|
| 195 |
-
return f"Please perform a '{analysis_type}' analysis on the data found at {data_uri}."
|
| 196 |
-
```
|
| 197 |
-
|
| 198 |
-
- **`name`**: Sets the explicit prompt name exposed via MCP.
|
| 199 |
-
- **`description`**: Provides the description exposed via MCP. If set, the function's docstring is ignored for this purpose.
|
| 200 |
-
- **`tags`**: A set of strings used to categorize the prompt. Clients *might* use tags to filter or group available prompts.
|
| 201 |
-
- **`enabled`**: A boolean to enable or disable the prompt (defaults to `True`). See [Disabling Prompts](#disabling-prompts) for more information.
|
| 202 |
### Disabling Prompts
|
| 203 |
|
| 204 |
<VersionBadge version="2.8.0" />
|
|
|
|
| 57 |
Functions with `*args` or `**kwargs` are not supported as prompts. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn't possible with variable argument lists.
|
| 58 |
</Tip>
|
| 59 |
|
| 60 |
+
#### Decorator Arguments
|
| 61 |
+
|
| 62 |
+
While FastMCP infers the name and description from your function, you can override these and add additional metadata using arguments to the `@mcp.prompt` decorator:
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
@mcp.prompt(
|
| 66 |
+
name="analyze_data_request", # Custom prompt name
|
| 67 |
+
description="Creates a request to analyze data with specific parameters", # Custom description
|
| 68 |
+
tags={"analysis", "data"} # Optional categorization tags
|
| 69 |
+
)
|
| 70 |
+
def data_analysis_prompt(
|
| 71 |
+
data_uri: str = Field(description="The URI of the resource containing the data."),
|
| 72 |
+
analysis_type: str = Field(default="summary", description="Type of analysis.")
|
| 73 |
+
) -> str:
|
| 74 |
+
"""This docstring is ignored when description is provided."""
|
| 75 |
+
return f"Please perform a '{analysis_type}' analysis on the data found at {data_uri}."
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
<Card icon="code" title="@prompt Decorator Arguments">
|
| 79 |
+
<ParamField body="name" type="str | None">
|
| 80 |
+
Sets the explicit prompt name exposed via MCP. If not provided, uses the function name
|
| 81 |
+
</ParamField>
|
| 82 |
+
|
| 83 |
+
<ParamField body="description" type="str | None">
|
| 84 |
+
Provides the description exposed via MCP. If set, the function's docstring is ignored for this purpose
|
| 85 |
+
</ParamField>
|
| 86 |
+
|
| 87 |
+
<ParamField body="tags" type="set[str] | None">
|
| 88 |
+
A set of strings used to categorize the prompt. Clients might use tags to filter or group available prompts
|
| 89 |
+
</ParamField>
|
| 90 |
+
|
| 91 |
+
<ParamField body="enabled" type="bool" default="True">
|
| 92 |
+
A boolean to enable or disable the prompt. See [Disabling Prompts](#disabling-prompts) for more information
|
| 93 |
+
</ParamField>
|
| 94 |
+
</Card>
|
| 95 |
### Argument Types
|
| 96 |
|
| 97 |
<VersionBadge version="2.9.0" />
|
|
|
|
| 212 |
|
| 213 |
In this example, the client *must* provide `data_uri`. If `analysis_type` or `include_charts` are omitted, their default values will be used.
|
| 214 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
### Disabling Prompts
|
| 216 |
|
| 217 |
<VersionBadge version="2.8.0" />
|
docs/servers/resources.mdx
CHANGED
|
@@ -58,18 +58,9 @@ def get_config() -> dict:
|
|
| 58 |
* Resource Name: Taken from the function name (`get_greeting`).
|
| 59 |
* Resource Description: Taken from the function's docstring.
|
| 60 |
|
| 61 |
-
###
|
| 62 |
-
|
| 63 |
-
FastMCP automatically converts your function's return value into the appropriate MCP resource content:
|
| 64 |
-
|
| 65 |
-
- **`str`**: Sent as `TextResourceContents` (with `mime_type="text/plain"` by default).
|
| 66 |
-
- **`dict`, `list`, `pydantic.BaseModel`**: Automatically serialized to a JSON string and sent as `TextResourceContents` (with `mime_type="application/json"` by default).
|
| 67 |
-
- **`bytes`**: Base64 encoded and sent as `BlobResourceContents`. You should specify an appropriate `mime_type` (e.g., `"image/png"`, `"application/octet-stream"`).
|
| 68 |
-
- **`None`**: Results in an empty resource content list being returned.
|
| 69 |
-
|
| 70 |
-
### Resource Metadata
|
| 71 |
|
| 72 |
-
You can customize the resource's properties using arguments in the decorator:
|
| 73 |
|
| 74 |
```python
|
| 75 |
from fastmcp import FastMCP
|
|
@@ -89,12 +80,40 @@ def get_application_status() -> dict:
|
|
| 89 |
return {"status": "ok", "uptime": 12345, "version": mcp.settings.version} # Example usage
|
| 90 |
```
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
### Disabling Resources
|
| 100 |
|
|
|
|
| 58 |
* Resource Name: Taken from the function name (`get_greeting`).
|
| 59 |
* Resource Description: Taken from the function's docstring.
|
| 60 |
|
| 61 |
+
#### Decorator Arguments
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
You can customize the resource's properties using arguments in the `@mcp.resource` decorator:
|
| 64 |
|
| 65 |
```python
|
| 66 |
from fastmcp import FastMCP
|
|
|
|
| 80 |
return {"status": "ok", "uptime": 12345, "version": mcp.settings.version} # Example usage
|
| 81 |
```
|
| 82 |
|
| 83 |
+
<Card icon="code" title="@resource Decorator Arguments">
|
| 84 |
+
<ParamField body="uri" type="str" required>
|
| 85 |
+
The unique identifier for the resource
|
| 86 |
+
</ParamField>
|
| 87 |
+
|
| 88 |
+
<ParamField body="name" type="str | None">
|
| 89 |
+
A human-readable name. If not provided, defaults to function name
|
| 90 |
+
</ParamField>
|
| 91 |
+
|
| 92 |
+
<ParamField body="description" type="str | None">
|
| 93 |
+
Explanation of the resource. If not provided, defaults to docstring
|
| 94 |
+
</ParamField>
|
| 95 |
+
|
| 96 |
+
<ParamField body="mime_type" type="str | None">
|
| 97 |
+
Specifies the content type. FastMCP often infers a default like `text/plain` or `application/json`, but explicit is better for non-text types
|
| 98 |
+
</ParamField>
|
| 99 |
+
|
| 100 |
+
<ParamField body="tags" type="set[str] | None">
|
| 101 |
+
A set of strings for categorization, potentially used by clients for filtering
|
| 102 |
+
</ParamField>
|
| 103 |
+
|
| 104 |
+
<ParamField body="enabled" type="bool" default="True">
|
| 105 |
+
A boolean to enable or disable the resource. See [Disabling Resources](#disabling-resources) for more information
|
| 106 |
+
</ParamField>
|
| 107 |
+
</Card>
|
| 108 |
+
|
| 109 |
+
### Return Values
|
| 110 |
+
|
| 111 |
+
FastMCP automatically converts your function's return value into the appropriate MCP resource content:
|
| 112 |
+
|
| 113 |
+
- **`str`**: Sent as `TextResourceContents` (with `mime_type="text/plain"` by default).
|
| 114 |
+
- **`dict`, `list`, `pydantic.BaseModel`**: Automatically serialized to a JSON string and sent as `TextResourceContents` (with `mime_type="application/json"` by default).
|
| 115 |
+
- **`bytes`**: Base64 encoded and sent as `BlobResourceContents`. You should specify an appropriate `mime_type` (e.g., `"image/png"`, `"application/octet-stream"`).
|
| 116 |
+
- **`None`**: Results in an empty resource content list being returned.
|
| 117 |
|
| 118 |
### Disabling Resources
|
| 119 |
|
docs/servers/server.mdx
CHANGED
|
@@ -31,13 +31,31 @@ mcp_with_instructions = FastMCP(
|
|
| 31 |
|
| 32 |
The `FastMCP` constructor accepts several arguments:
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
## Components
|
| 42 |
|
| 43 |
FastMCP servers expose several types of components to the client:
|
|
@@ -235,6 +253,34 @@ mcp = FastMCP(
|
|
| 235 |
)
|
| 236 |
```
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
### Global Settings
|
| 239 |
|
| 240 |
Global settings affect all FastMCP servers and can be configured via environment variables (prefixed with `FASTMCP_`) or in a `.env` file:
|
|
|
|
| 31 |
|
| 32 |
The `FastMCP` constructor accepts several arguments:
|
| 33 |
|
| 34 |
+
<Card icon="code" title="FastMCP Constructor Parameters">
|
| 35 |
+
<ParamField body="name" type="str" default="FastMCP">
|
| 36 |
+
A human-readable name for your server
|
| 37 |
+
</ParamField>
|
| 38 |
+
|
| 39 |
+
<ParamField body="instructions" type="str | None">
|
| 40 |
+
Description of how to interact with this server. These instructions help clients understand the server's purpose and available functionality
|
| 41 |
+
</ParamField>
|
| 42 |
+
|
| 43 |
+
<ParamField body="lifespan" type="AsyncContextManager | None">
|
| 44 |
+
An async context manager function for server startup and shutdown logic
|
| 45 |
+
</ParamField>
|
| 46 |
+
|
| 47 |
+
<ParamField body="tags" type="set[str] | None">
|
| 48 |
+
A set of strings to tag the server itself
|
| 49 |
+
</ParamField>
|
| 50 |
+
|
| 51 |
+
<ParamField body="tools" type="list[Tool | Callable] | None">
|
| 52 |
+
A list of tools (or functions to convert to tools) to add to the server. In some cases, providing tools programmatically may be more convenient than using the `@mcp.tool` decorator
|
| 53 |
+
</ParamField>
|
| 54 |
+
|
| 55 |
+
<ParamField body="**settings" type="Any">
|
| 56 |
+
Keyword arguments corresponding to additional `ServerSettings` configuration
|
| 57 |
+
</ParamField>
|
| 58 |
+
</Card>
|
| 59 |
## Components
|
| 60 |
|
| 61 |
FastMCP servers expose several types of components to the client:
|
|
|
|
| 253 |
)
|
| 254 |
```
|
| 255 |
|
| 256 |
+
### Constructor Parameters
|
| 257 |
+
|
| 258 |
+
<Card icon="code" title="AdditionalFastMCP Constructor Parameters">
|
| 259 |
+
<ParamField body="dependencies" type="list[str] | None">
|
| 260 |
+
Optional server dependencies list with package specifications
|
| 261 |
+
</ParamField>
|
| 262 |
+
|
| 263 |
+
<ParamField body="include_tags" type="set[str] | None">
|
| 264 |
+
Only expose components with at least one matching tag
|
| 265 |
+
</ParamField>
|
| 266 |
+
|
| 267 |
+
<ParamField body="exclude_tags" type="set[str] | None">
|
| 268 |
+
Hide components with any matching tag
|
| 269 |
+
</ParamField>
|
| 270 |
+
|
| 271 |
+
<ParamField body="on_duplicate_tools" type='Literal["error", "warn", "replace"]' default="error">
|
| 272 |
+
How to handle duplicate tool registrations
|
| 273 |
+
</ParamField>
|
| 274 |
+
|
| 275 |
+
<ParamField body="on_duplicate_resources" type='Literal["error", "warn", "replace"]' default="warn">
|
| 276 |
+
How to handle duplicate resource registrations
|
| 277 |
+
</ParamField>
|
| 278 |
+
|
| 279 |
+
<ParamField body="on_duplicate_prompts" type='Literal["error", "warn", "replace"]' default="replace">
|
| 280 |
+
How to handle duplicate prompt registrations
|
| 281 |
+
</ParamField>
|
| 282 |
+
</Card>
|
| 283 |
+
|
| 284 |
### Global Settings
|
| 285 |
|
| 286 |
Global settings affect all FastMCP servers and can be configured via environment variables (prefixed with `FASTMCP_`) or in a `.env` file:
|
docs/servers/tools.mdx
CHANGED
|
@@ -49,9 +49,68 @@ The way you define your Python function dictates how the tool appears and behave
|
|
| 49 |
Functions with `*args` or `**kwargs` are not supported as tools. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn't possible with variable argument lists.
|
| 50 |
</Tip>
|
| 51 |
|
| 52 |
-
###
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
Type annotations for parameters are essential for proper tool functionality. They:
|
| 57 |
1. Inform the LLM about the expected data types for each parameter
|
|
@@ -150,28 +209,6 @@ def search_products(
|
|
| 150 |
|
| 151 |
In this example, the LLM must provide a `query` parameter, while `max_results`, `sort_by`, and `category` will use their default values if not explicitly provided.
|
| 152 |
|
| 153 |
-
### Metadata
|
| 154 |
-
|
| 155 |
-
While FastMCP infers the name and description from your function, you can override these and add tags using arguments to the `@mcp.tool` decorator:
|
| 156 |
-
|
| 157 |
-
```python
|
| 158 |
-
@mcp.tool(
|
| 159 |
-
name="find_products", # Custom tool name for the LLM
|
| 160 |
-
description="Search the product catalog with optional category filtering.", # Custom description
|
| 161 |
-
tags={"catalog", "search"}, # Optional tags for organization/filtering
|
| 162 |
-
)
|
| 163 |
-
def search_products_implementation(query: str, category: str | None = None) -> list[dict]:
|
| 164 |
-
"""Internal function description (ignored if description is provided above)."""
|
| 165 |
-
# Implementation...
|
| 166 |
-
print(f"Searching for '{query}' in category '{category}'")
|
| 167 |
-
return [{"id": 2, "name": "Another Product"}]
|
| 168 |
-
```
|
| 169 |
-
|
| 170 |
-
- **`name`**: Sets the explicit tool name exposed via MCP.
|
| 171 |
-
- **`description`**: Provides the description exposed via MCP. If set, the function's docstring is ignored for this purpose.
|
| 172 |
-
- **`tags`**: A set of strings to categorize the tool. Clients *might* use tags to filter or group available tools.
|
| 173 |
-
- **`enabled`**: A boolean to enable or disable the tool (defaults to `True`). See [Disabling Tools](#disabling-tools) for more information.
|
| 174 |
-
- **`exclude_args`**: A list of argument names to exclude from the tool schema shown to the LLM. See [Excluding Arguments](#excluding-arguments) for more information.
|
| 175 |
|
| 176 |
### Excluding Arguments
|
| 177 |
|
|
|
|
| 49 |
Functions with `*args` or `**kwargs` are not supported as tools. This restriction exists because FastMCP needs to generate a complete parameter schema for the MCP protocol, which isn't possible with variable argument lists.
|
| 50 |
</Tip>
|
| 51 |
|
| 52 |
+
#### Decorator Arguments
|
| 53 |
|
| 54 |
+
While FastMCP infers the name and description from your function, you can override these and add additional metadata using arguments to the `@mcp.tool` decorator:
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
@mcp.tool(
|
| 58 |
+
name="find_products", # Custom tool name for the LLM
|
| 59 |
+
description="Search the product catalog with optional category filtering.", # Custom description
|
| 60 |
+
tags={"catalog", "search"}, # Optional tags for organization/filtering
|
| 61 |
+
)
|
| 62 |
+
def search_products_implementation(query: str, category: str | None = None) -> list[dict]:
|
| 63 |
+
"""Internal function description (ignored if description is provided above)."""
|
| 64 |
+
# Implementation...
|
| 65 |
+
print(f"Searching for '{query}' in category '{category}'")
|
| 66 |
+
return [{"id": 2, "name": "Another Product"}]
|
| 67 |
+
```
|
| 68 |
+
|
| 69 |
+
<Card icon="code" title="@tool Decorator Arguments">
|
| 70 |
+
<ParamField body="name" type="str | None">
|
| 71 |
+
Sets the explicit tool name exposed via MCP. If not provided, uses the function name
|
| 72 |
+
</ParamField>
|
| 73 |
+
|
| 74 |
+
<ParamField body="description" type="str | None">
|
| 75 |
+
Provides the description exposed via MCP. If set, the function's docstring is ignored for this purpose
|
| 76 |
+
</ParamField>
|
| 77 |
+
|
| 78 |
+
<ParamField body="tags" type="set[str] | None">
|
| 79 |
+
A set of strings to categorize the tool. Clients might use tags to filter or group available tools
|
| 80 |
+
</ParamField>
|
| 81 |
+
|
| 82 |
+
<ParamField body="enabled" type="bool" default="True">
|
| 83 |
+
A boolean to enable or disable the tool. See [Disabling Tools](#disabling-tools) for more information
|
| 84 |
+
</ParamField>
|
| 85 |
+
|
| 86 |
+
<ParamField body="exclude_args" type="list[str] | None">
|
| 87 |
+
A list of argument names to exclude from the tool schema shown to the LLM. See [Excluding Arguments](#excluding-arguments) for more information
|
| 88 |
+
</ParamField>
|
| 89 |
+
|
| 90 |
+
<ParamField body="annotations" type="ToolAnnotations | dict | None">
|
| 91 |
+
An optional `ToolAnnotations` object or dictionary to add additional metadata about the tool.
|
| 92 |
+
<Expandable title="ToolAnnotations attributes">
|
| 93 |
+
<ParamField body="title" type="str | None">
|
| 94 |
+
A human-readable title for the tool.
|
| 95 |
+
</ParamField>
|
| 96 |
+
<ParamField body="readOnlyHint" type="bool | None">
|
| 97 |
+
If true, the tool does not modify its environment.
|
| 98 |
+
</ParamField>
|
| 99 |
+
<ParamField body="destructiveHint" type="bool | None">
|
| 100 |
+
If true, the tool may perform destructive updates to its environment.
|
| 101 |
+
</ParamField>
|
| 102 |
+
<ParamField body="idempotentHint" type="bool | None">
|
| 103 |
+
If true, calling the tool repeatedly with the same arguments will have no additional effect on the its environment.
|
| 104 |
+
</ParamField>
|
| 105 |
+
<ParamField body="openWorldHint" type="bool | None">
|
| 106 |
+
If true, this tool may interact with an "open world" of external entities. If false, the tool's domain of interaction is closed.
|
| 107 |
+
</ParamField>
|
| 108 |
+
</Expandable>
|
| 109 |
+
</ParamField>
|
| 110 |
+
</Card>
|
| 111 |
+
### Tool Parameters
|
| 112 |
+
|
| 113 |
+
#### Type Annotations
|
| 114 |
|
| 115 |
Type annotations for parameters are essential for proper tool functionality. They:
|
| 116 |
1. Inform the LLM about the expected data types for each parameter
|
|
|
|
| 209 |
|
| 210 |
In this example, the LLM must provide a `query` parameter, while `max_results`, `sort_by`, and `category` will use their default values if not explicitly provided.
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
### Excluding Arguments
|
| 214 |
|