Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

feat(mcp-host): validate attachment retention limits

Alfredo Lopezc25494bbf24a
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 10cb1d7b7..679ca3bdb 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.482",
+ "version": "0.1.483",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.482",
+ "version": "0.1.483",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 30b90dae3..01f45cfd7 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.482",
+ "version": "0.1.483",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/config.attachmentStore.test.ts b/mcp-host/src/config.attachmentStore.test.ts
new file mode 100644
index 000000000..771dae488
--- /dev/null
+++ b/mcp-host/src/config.attachmentStore.test.ts
@@ -0,0 +1,72 @@
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+const TTL = 'CLERUM_ATTACHMENT_STORE_TTL_HOURS'
+const SESSION = 'CLERUM_ATTACHMENT_STORE_SESSION_MAX_BYTES'
+const HOST = 'CLERUM_ATTACHMENT_STORE_HOST_MAX_BYTES'
+
+afterEach(() => {
+ vi.unstubAllEnvs()
+ vi.resetModules()
+})
+
+async function load() {
+ vi.resetModules()
+ return (await import('./config')).config
+}
+
+describe('attachment retention configuration', () => {
+ it('defaults to seven days, 64 MiB per session and 1 GiB per Host', async () => {
+ vi.stubEnv(TTL, undefined)
+ vi.stubEnv(SESSION, undefined)
+ vi.stubEnv(HOST, undefined)
+ const config = await load()
+ expect(config).toMatchObject({
+ attachmentStoreTtlMs: 604_800_000,
+ attachmentStoreSessionMaxBytes: 67_108_864,
+ attachmentStoreHostMaxBytes: 1_073_741_824,
+ })
+ })
+
+ it.each([TTL, SESSION, HOST])('rejects invalid %s instead of using its default', async key => {
+ for (const value of ['', '0', '-1', '1.5', '1e6', '12hours', 'Infinity', '9007199254740992']) {
+ vi.stubEnv(key, value)
+ await expect(load()).rejects.toThrow(key)
+ }
+ })
+
+ it('accepts explicitly configured limits without changing the upload limit', async () => {
+ vi.stubEnv(TTL, '24')
+ vi.stubEnv(SESSION, '12582912')
+ vi.stubEnv(HOST, '33554432')
+ const config = await load()
+ expect(config).toMatchObject({
+ attachmentStoreTtlMs: 86_400_000,
+ attachmentStoreSessionMaxBytes: 12_582_912,
+ attachmentStoreHostMaxBytes: 33_554_432,
+ attachmentFileMaxBytes: 11_534_336,
+ })
+ })
+
+ it('rejects a session cap greater than the Host cap', async () => {
+ vi.stubEnv(SESSION, '67108864')
+ vi.stubEnv(HOST, '33554432')
+ await expect(load()).rejects.toThrow(SESSION)
+ })
+
+ it('requires space for one admitted file and honors a smaller configured file limit', async () => {
+ vi.stubEnv(SESSION, '11534335')
+ await expect(load()).rejects.toThrow(SESSION)
+ vi.stubEnv('CLERUM_ATTACHMENT_FILE_MAX_BYTES', '3145728')
+ vi.stubEnv(SESSION, '3145728')
+ vi.stubEnv(HOST, '3145728')
+ expect(await load()).toMatchObject({
+ attachmentStoreSessionMaxBytes: 3_145_728,
+ attachmentStoreHostMaxBytes: 3_145_728,
+ })
+ })
+
+ it('rejects a TTL that cannot produce a valid absolute JavaScript date', async () => {
+ vi.stubEnv(TTL, '2400000000')
+ await expect(load()).rejects.toThrow(TTL)
+ })
+})
diff --git a/mcp-host/src/config.ts b/mcp-host/src/config.ts
index 612f74c88..aff9a80fc 100644
--- a/mcp-host/src/config.ts
+++ b/mcp-host/src/config.ts
@@ -249,6 +249,11 @@ export interface Config {
attachmentFileMaxBytes: number
/** Bytes one `clerum__attachment_read` call may return (issue #666). */
attachmentTextReadMaxBytes: number
+ /** Absolute retention duration; reads never extend it. */
+ attachmentStoreTtlMs: number
+ /** Committed, reserved and pending-cleanup bytes share these quotas. */
+ attachmentStoreSessionMaxBytes: number
+ attachmentStoreHostMaxBytes: number
/**
* Structured file references one incoming message may carry (issue #666).
* The shared contract constant the Desktop composer also enforces; not
@@ -514,6 +519,40 @@ const attachmentTextReadMaxBytes = getExecutionLimit(
false,
1_048_576
)
+const attachmentFileMaxBytes = getExecutionLimit(
+ 'CLERUM_ATTACHMENT_FILE_MAX_BYTES',
+ 11_534_336,
+ false,
+ 11_534_336
+)
+const attachmentStoreTtlHours = getExecutionLimit(
+ 'CLERUM_ATTACHMENT_STORE_TTL_HOURS',
+ 168,
+ false,
+ // Date's absolute limit is stricter than the safe-integer limit. Admission
+ // must also check its trusted timestamp before adding this duration.
+ Math.floor((8_640_000_000_000_000 - Date.now()) / 3_600_000)
+)
+const attachmentStoreSessionMaxBytes = getExecutionLimit(
+ 'CLERUM_ATTACHMENT_STORE_SESSION_MAX_BYTES',
+ 67_108_864,
+ false,
+ Number.MAX_SAFE_INTEGER
+)
+const attachmentStoreHostMaxBytes = getExecutionLimit(
+ 'CLERUM_ATTACHMENT_STORE_HOST_MAX_BYTES',
+ 1_073_741_824,
+ false,
+ Number.MAX_SAFE_INTEGER
+)
+if (
+ attachmentStoreSessionMaxBytes < attachmentFileMaxBytes ||
+ attachmentStoreSessionMaxBytes > attachmentStoreHostMaxBytes
+) {
+ throw new Error(
+ 'CLERUM_ATTACHMENT_STORE_SESSION_MAX_BYTES must accommodate one admitted file and not exceed CLERUM_ATTACHMENT_STORE_HOST_MAX_BYTES'
+ )
+}
const configuredWorkflowEnabled = getEnvBool('CLERUM_WORKFLOW_ENABLED', false)
const configuredRuntimeKind = resolveMcpHostRuntimeKind({
workflowEnabled: configuredWorkflowEnabled,
@@ -1045,13 +1084,11 @@ export const config: Config = {
enableResponseAttachments: getEnvBool('CLERUM_ENABLE_RESPONSE_ATTACHMENTS', true),
attachmentMaxCount: parseInt(getEnv('CLERUM_ATTACHMENT_MAX_COUNT', '3')!, 10),
attachmentMaxBytes: parseInt(getEnv('CLERUM_ATTACHMENT_MAX_BYTES', '52428800')!, 10),
- attachmentFileMaxBytes: getExecutionLimit(
- 'CLERUM_ATTACHMENT_FILE_MAX_BYTES',
- 11_534_336,
- false,
- 11_534_336
- ),
+ attachmentFileMaxBytes,
attachmentTextReadMaxBytes,
+ attachmentStoreTtlMs: attachmentStoreTtlHours * 3_600_000,
+ attachmentStoreSessionMaxBytes,
+ attachmentStoreHostMaxBytes,
fileReferenceMaxCount: FILE_REFERENCE_MAX_COUNT,
activityBufferSize: parseInt(getEnv('MCP_HOST_ACTIVITY_BUFFER_SIZE', '1000')!, 10),
activityMaxEventBytes: parseInt(getEnv('MCP_HOST_ACTIVITY_MAX_EVENT_BYTES', '2048')!, 10),