Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions packages/schemas/src/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { z } from "zod";
import { PlatformInfoSchema } from "./api-responses.js";

// =============================================================================
// Cache Metadata
// =============================================================================

/**
* Zod schema for the `.mpak-meta.json` file written alongside cached bundles.
*
* `.strict()` rejects unknown fields so corrupted or hand-edited files
* are caught on read rather than silently accepted.
*/
export const CacheMetadataSchema = z
.object({
version: z.string(),
pulledAt: z.string(),
lastCheckedAt: z.string().optional(),
platform: PlatformInfoSchema,
})
.strict();

export type CacheMetadata = z.infer<typeof CacheMetadataSchema>;

// =============================================================================
// Cached Bundle Info
// =============================================================================

/**
* Summary of a bundle stored in the local cache.
* Returned by `BundleCache.listCachedBundles()` and consumed by CLI
* commands like `mpak outdated`.
*/
export interface CachedBundleInfo {
name: string;
version: string;
pulledAt: string;
cacheDir: string;
}
6 changes: 6 additions & 0 deletions packages/schemas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,11 @@ export * from "./skill.js";
// mpak.json schema and utilities
export * from "./mpak-json.js";

// Versioned manifest schemas
export * from "./manifest.js";

// Cache metadata
export * from "./cache.js";

// Validation helpers
export * from "./validation.js";
90 changes: 90 additions & 0 deletions packages/schemas/src/manifest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { z } from "zod";

// =============================================================================
// Manifest Building Blocks
// =============================================================================

/** Server runtime type (v0.4 added "uv"). */
export const ServerTypeSchema = z.enum(["node", "python", "binary", "uv"]);

/** User-configurable field declared by a bundle author. */
export const UserConfigFieldSchema = z.object({
type: z.enum(["string", "number", "boolean"]),
title: z.string().optional(),
description: z.string().optional(),
sensitive: z.boolean().optional(),
required: z.boolean().optional(),
default: z.union([z.string(), z.number(), z.boolean()]).optional(),
});

/** MCP server launch configuration (command, args, env). */
export const McpConfigSchema = z.object({
command: z.string(),
args: z.array(z.string()),
env: z.record(z.string(), z.string()).optional(),
});

/** Author information. */
export const ManifestAuthorSchema = z.object({
name: z.string(),
email: z.string().optional(),
url: z.string().optional(),
});

/** Server configuration block. */
export const ManifestServerSchema = z.object({
type: ServerTypeSchema,
entry_point: z.string(),
mcp_config: McpConfigSchema,
});

/** MCP capability descriptor (tool, prompt, or resource). */
export const CapabilitySchema = z.object({
name: z.string(),
description: z.string().optional(),
});

// =============================================================================
// MCPB Manifest Schema
// =============================================================================

/**
* MCPB bundle manifest.
*
* Compatible with both v0.3 and v0.4 of the upstream spec.
* The two versions are backward-compatible (v0.4 only adds "uv" server type).
*/
export const McpbManifestSchema = z.object({
manifest_version: z.string(),
name: z.string(),
version: z.string(),
description: z.string(),
display_name: z.string().optional(),
author: ManifestAuthorSchema.optional(),
homepage: z.string().optional(),
license: z.string().optional(),
icon: z.string().optional(),
repository: z
.object({
type: z.string().optional(),
url: z.string().optional(),
})
.optional(),
user_config: z.record(z.string(), UserConfigFieldSchema).optional(),
server: ManifestServerSchema,
tools: z.array(CapabilitySchema).optional(),
prompts: z.array(CapabilitySchema).optional(),
resources: z.array(CapabilitySchema).optional(),
_meta: z.record(z.string(), z.unknown()).optional(),
});

// =============================================================================
// TypeScript Types
// =============================================================================

export type ServerType = z.infer<typeof ServerTypeSchema>;
export type UserConfigField = z.infer<typeof UserConfigFieldSchema>;
export type McpConfig = z.infer<typeof McpConfigSchema>;
export type ManifestAuthor = z.infer<typeof ManifestAuthorSchema>;
export type ManifestServer = z.infer<typeof ManifestServerSchema>;
export type McpbManifest = z.infer<typeof McpbManifestSchema>;
23 changes: 19 additions & 4 deletions packages/schemas/src/package.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
import { z } from "zod";

import { ServerTypeSchema } from "./manifest.js";

// Re-export manifest schemas so existing consumers of package.ts are not broken.
export {
CapabilitySchema,
ManifestAuthorSchema,
ManifestServerSchema,
McpbManifestSchema,
McpConfigSchema,
ServerTypeSchema,
UserConfigFieldSchema,
type ManifestAuthor,
type ManifestServer,
type McpbManifest,
type McpConfig,
type ServerType,
type UserConfigField,
} from "./manifest.js";

// =============================================================================
// Enums & Search Params
// =============================================================================

/** Server runtime type */
export const ServerTypeSchema = z.enum(["node", "python", "binary"]);

/** Supported operating system platforms */
export const PlatformSchema = z.enum(["darwin", "win32", "linux"]);

Expand Down Expand Up @@ -47,7 +63,6 @@ export const BundleDownloadParamsSchema = z.object({
// TypeScript Types
// =============================================================================

export type ServerType = z.infer<typeof ServerTypeSchema>;
export type Platform = z.infer<typeof PlatformSchema>;
export type PackageSort = z.infer<typeof PackageSortSchema>;
export type PackageSearchParams = z.infer<typeof PackageSearchParamsSchema>;
Expand Down
Loading
Loading