Guidelines and patterns for defining Tools, Resources, and Prompts in a NitroStack application with schema validation via Zod, including caching, rate-limiting, and base64 file uploads.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Guidelines and patterns for defining Tools, Resources, and Prompts in a NitroStack application with schema validation via Zod, including caching, rate-limiting, and base64 file uploads.
When to Use
Use this skill whenever you are defining, editing, or validating tools, resources, or prompts on a NitroStack MCP server.
Defining Tools with @Tool
An MCP tool exposes a function that an AI client can invoke. Decorate a service or controller method with @Tool.
Key Tool Options:
name: Kebab-case or snake_case unique identifier.
description: Detailed description explaining when and how the client should use it.
inputSchema: A Zod object schema for strict validation of inputs.
outputSchema (optional): Zod schema validating the output structure.
An MCP prompt exposes reusable templates or instruction sets that guide LLMs.
Key Prompt Options:
name: Name of the prompt.
description: Describes what task this prompt helps accomplish.
arguments: Declares parameters the client can supply to customize the prompt template.
import { Prompt, ExecutionContext } from'@nitrostack/core';
exportclassPromptTemplates {
@Prompt({
name: 'code_review',
description: 'Provide an intensive code review for a given code snippet.',
arguments: [
{ name: 'language', description: 'The programming language, e.g., TypeScript', required: true },
{ name: 'code', description: 'The code snippet to review', required: true },
],
})
asyncgetCodeReviewPrompt(args: { language: string; code: string },
ctx: ExecutionContext) {
return {
messages: [
{
role: 'user',
content: `You are an expert software engineer. Review this ${args.language} code:\n\n${args.code}`,
},
],
};
}
}
Tool Policies: Caching (@Cache) and Rate Limiting (@RateLimit)
You can control tool execution behaviors (such as performance optimization and throttling) using method decorators.
1. Caching with @Cache
Use @Cache to cache tool execution outputs for a specified duration (TTL in seconds). This reduces database or API overhead for frequent identical requests.
Options:
ttl: Cache time-to-live in seconds (required).
key (optional): Custom function (input: any, context?: any) => string that returns a unique cache key based on inputs. If not defined, a key is auto-generated from serialized input arguments.
Example:
import { ToolDecoratorasTool, Cache, z } from'@nitrostack/core';
exportclassStationTools {
@Tool({
name: 'get_system_status',
description: 'Fetch real-time station metrics. Response is cached.',
inputSchema: z.object({}),
})
@Cache({ ttl: 60 }) // Caches status for 60 secondsasyncgetSystemStatus() {
return { temperature: 21.5, oxygen: 0.98 };
}
@Tool({
name: 'get_crew_status',
description: 'Fetch status of a crew member. Cached by crew ID.',
inputSchema: z.object({ id: z.string() }),
})
@Cache({
ttl: 300,
key: (input) =>`crew:status:${input.id}`
})
asyncgetCrewStatus(input: { id: string }) {
// ...
}
}
2. Rate Limiting with @RateLimit
Use @RateLimit to restrict the number of tool invocations within a specified time window to prevent client abuse.
Options:
requests: Number of allowed requests in the window (required).