Skip to content
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7757305
feat: enhance context-aware proxy functionality and template processing
xizhibei Dec 15, 2025
8f139a8
test: enhance context and template processing tests
xizhibei Dec 15, 2025
9bd9013
feat: introduce context-aware template processing and configuration m…
xizhibei Dec 15, 2025
beb659b
refactor: streamline context handling and enhance template processing
xizhibei Dec 16, 2025
36c796e
feat: enhance security in command execution and path handling
xizhibei Dec 17, 2025
5cda100
feat: enhance server instance management with template settings and c…
xizhibei Dec 19, 2025
66ad78f
feat: implement client instance pooling and enhance configuration man…
xizhibei Dec 20, 2025
e4eaf06
test: enhance internal capabilities provider tests with mocking and i…
xizhibei Dec 20, 2025
dfbbd6f
feat: introduce connection and lifecycle management for MCP servers
xizhibei Dec 20, 2025
169fc62
feat: enhance template processing and validation for transport types
xizhibei Dec 20, 2025
6f4ae1f
refactor: migrate to Handlebars for template rendering and enhance co…
xizhibei Dec 21, 2025
d9e58be
refactor: remove ContextCollector and related tests to streamline con…
xizhibei Dec 21, 2025
73c08ae
fix: update template variable syntax for consistency in session conte…
xizhibei Dec 21, 2025
b01f743
fix: update test project paths in HandlebarsTemplateRenderer tests
xizhibei Dec 21, 2025
9c9bcf7
feat: add comprehensive integration tests for cross-domain operations
xizhibei Dec 21, 2025
3af0d4a
feat: enhance client information handling in transport and configurat…
xizhibei Dec 22, 2025
65f5502
feat: enhance session and transport context management
xizhibei Dec 22, 2025
dcd21f9
feat: add tags option for server selection and enhance session contex…
xizhibei Dec 22, 2025
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
92 changes: 92 additions & 0 deletions .1mcprc.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,96 @@
// Option 3: Use simple tags (lowest priority)
// "tags": ["web", "api", "database"],
// "tags": "web,api,database" // String format also supported

// Enable context-aware proxy mode (NEW!)
"context": {
// Project identifier for template substitution
"projectId": "my-awesome-app",

// Environment for template substitution
"environment": "development",

// Team or organization identifier
"team": "platform",

// Custom context variables available in templates
"custom": {
"apiEndpoint": "https://api.dev.local",
"featureFlags": ["new-ui", "beta-api"],
"debugMode": true
},

// Environment variable prefixes to include in context
"envPrefixes": ["MY_APP_", "API_"],

// Enable/disable git information collection
"includeGit": true,

// Sanitize file paths (replace home directory with ~)
"sanitizePaths": true
}
}

/*
Template Examples for MCP Server Configurations:

When context is enabled, you can use templates in your MCP server configurations:

{
"name": "project-aware-serena",
"command": "npx",
"args": [
"-y",
"serena",
"{project.path}", // Current working directory
"{project.name}", // Project name from context
"{project.environment}", // Environment from context
"{user.username}", // Current user
"{project.custom.apiEndpoint}", // Custom context variable
"{context.timestamp}" // Current timestamp
],
"env": {
"PROJECT_ID": "{project.custom.projectId}",
"USER_TEAM": "{project.custom.team}",
"GIT_BRANCH": "{project.git.branch?:main}",
"SESSION_ID": "{context.sessionId}"
}
}

Available Template Variables:

Project Context:
{project.path} - Current working directory
{project.name} - Project directory name
{project.environment} - Environment from context config
{project.git.branch} - Current git branch (if git repo)
{project.git.commit} - Current git commit (short hash)
{project.git.repository} - Git repository name
{project.custom.*} - Custom variables from context

User Context:
{user.username} - Current system username
{user.name} - User's display name
{user.email} - User's email (from git config)
{user.home} - User's home directory

Environment Context:
{environment.variables.*} - Environment variables
{context.path} - Alias for {project.path}
{context.timestamp} - Current ISO timestamp
{context.sessionId} - Unique session identifier
{context.version} - Context schema version

Template Functions:
{variable | upper} - Convert to uppercase
{variable | lower} - Convert to lowercase
{variable | capitalize} - Capitalize words
{variable | truncate(10)} - Truncate to length
{variable | replace(from,to)}- Replace text
{variable | basename} - Get filename from path
{variable | dirname} - Get directory from path
{variable | extname} - Get file extension
{variable | default(value)} - Default value if empty

Example: "{project.name | upper}-{context.timestamp | date('YYYY-MM-DD')}"
*/
104 changes: 104 additions & 0 deletions mcp.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"version": "1.0.0",
"templateSettings": {
"validateOnReload": true,
"failureMode": "graceful",
"cacheContext": true
},
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
"env": {},
"tags": ["filesystem"]
},
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
},
"tags": ["git", "development"]
},
"postgres": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-postgres"],
"env": {
"DATABASE_URL": "${DATABASE_URL}"
},
"tags": ["database", "production"]
}
},
"mcpTemplates": {
"project-serena": {
"command": "npx",
"args": [
"-y",
"serena",
"{project.path}",
"--project", "{project.name}",
"--env", "{project.environment}",
"--team", "{project.custom.team}"
],
"env": {
"PROJECT_ID": "{project.custom.projectId}",
"SESSION_ID": "{context.sessionId}",
"GIT_BRANCH": "{project.git.branch?:main}",
"API_ENDPOINT": "{project.custom.apiEndpoint}"
},
"tags": ["filesystem", "search"]
},
"context-server": {
"command": "node",
"args": ["{project.path}/servers/context.js"],
"cwd": "{project.path}",
"env": {
"PROJECT_NAME": "{project.name | upper}",
"USER_NAME": "{user.username}",
"TIMESTAMP": "{context.timestamp | date('YYYY-MM-DD')}",
"DEBUG": "{?project.custom.debugMode:true:false}"
},
"tags": ["context-aware", "development"],
"disabled": "{?project.environment=production}"
},
"api-server": {
"command": "node",
"args": ["{project.path}/api/server.js"],
"env": {
"API_ENDPOINT": "{project.custom.apiEndpoint}",
"NODE_ENV": "{project.environment}",
"PROJECT_ID": "{project.custom.projectId}",
"TEAM": "{project.custom.team}"
},
"cwd": "{project.path}/services",
"tags": ["api", "development"]
},
"team-tools": {
"command": "npx",
"args": ["-y", "serena", "{project.path}"],
"env": {
"PROJECT_NAME": "{project.name}",
"TEAM_NAME": "{project.custom.team}",
"USER_ROLE": "{user.custom.role}",
"API_ENDPOINT": "{project.custom.apiEndpoint}",
"ENVIRONMENT": "{project.environment}",
"PROJECT_ID": "{project.custom.projectId}",
"SESSION_ID": "{context.sessionId}"
},
"tags": ["{project.custom.team}", "development"],
"cwd": "{project.path}"
},
"conditional-server": {
"command": "node",
"args": ["{project.path}/conditional-server.js"],
"cwd": "{project.path}",
"env": {
"NODE_ENV": "{project.environment}",
"DEBUG": "{?project.environment=development:true}",
"LOG_LEVEL": "{?project.environment=production:warn:debug}"
},
"tags": ["utility"],
"disabled": "{?project.environment=production}"
}
}
}
1 change: 1 addition & 0 deletions src/application/services/healthService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ vi.mock('@src/logger/logger.js', () => ({
warn: vi.fn(),
debug: vi.fn(),
},
debugIf: vi.fn(),
}));

vi.mock('@src/core/server/serverManager.js', () => ({
Expand Down
9 changes: 9 additions & 0 deletions src/auth/sessionTypes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Shared session types for server and client session managers
import { OAuthClientInformationFull } from '@modelcontextprotocol/sdk/shared/auth.js';

import { ContextNamespace, EnvironmentContext, UserContext } from '@src/types/context.js';

/**
* Base interface for all data that can expire
*/
Expand Down Expand Up @@ -54,4 +56,11 @@ export interface StreamableSessionData extends ExpirableData {
enablePagination?: boolean;
customTemplate?: string;
lastAccessedAt: number;
context?: {
project?: ContextNamespace;
user?: UserContext;
environment?: EnvironmentContext;
timestamp?: string;
version?: string;
};
}
1 change: 1 addition & 0 deletions src/auth/storage/authRequestRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ vi.mock('@src/logger/logger.js', () => ({
warn: vi.fn(),
debug: vi.fn(),
},
debugIf: vi.fn(),
}));

describe('AuthRequestRepository', () => {
Expand Down
1 change: 1 addition & 0 deletions src/auth/storage/clientDataRepository.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ vi.mock('@src/logger/logger.js', () => ({
warn: vi.fn(),
debug: vi.fn(),
},
debugIf: vi.fn(),
}));

describe('ClientDataRepository', () => {
Expand Down
1 change: 1 addition & 0 deletions src/commands/mcp/uninstall.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ vi.mock('@src/logger/logger.js', () => ({
info: vi.fn(),
error: vi.fn(),
},
debugIf: vi.fn(),
}));

const consoleLogMock = vi.fn();
Expand Down
1 change: 1 addition & 0 deletions src/commands/mcp/utils/mcpServerConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ vi.mock('@src/logger/logger.js', () => ({
warn: vi.fn(),
error: vi.fn(),
},
debugIf: vi.fn(),
}));

const mockSetServer = vi.mocked(setServer);
Expand Down
1 change: 1 addition & 0 deletions src/commands/mcp/utils/serverUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ vi.mock('@src/logger/logger.js', () => ({
default: {
debug: vi.fn(),
},
debugIf: vi.fn(),
}));

describe('serverUtils', () => {
Expand Down
Loading
Loading