Thank you for your interest in contributing to mcp-pty! This guide will help you get started with contributing to this MCP server project.
- Development Setup
- Project Structure
- Contribution Workflow
- Code Standards
- Testing Guidelines
- Documentation
- Security Considerations
- Release Process
- Bun v1.2.0+ (required runtime and package manager)
- Git for version control
- Node.js compatible environment (for some dev tools)
-
Fork and Clone
git clone https://github.com/your-username/mcp-pty.git cd mcp-pty -
Install Dependencies
bun install
-
Verify Setup
# Type checking bun check -
Run Tests
bun test
# Type checking
bun check
# Linting and formatting
bun run lint
bun run format
# Testing
bun test # All tests
bun test packages/pty-manager # Specific package
# Build
bun run build
# Development mode (with watch)
bun run devmcp-pty/
├── packages/
│ ├── mcp-pty/ # Main MCP server
│ ├── pty-manager/ # PTY process management
│ ├── session-manager/ # Session lifecycle
│ ├── normalize-commands/# Command parsing & security
│ ├── logger/ # Centralized logging
│ └── experiments/ # Experimental features
├── docs/ # Documentation
├── .github/ # GitHub workflows
└── tools/ # Build and dev tools
Each package follows this structure:
packages/package-name/
├── src/
│ ├── index.ts # Main exports
│ ├── types/ # TypeScript definitions
│ ├── utils/ # Utility functions
│ └── __tests__/ # Test files
├── package.json
├── tsconfig.json
└── README.md
- Search existing issues first
- Use appropriate labels (bug, enhancement, documentation)
- Provide clear description and reproduction steps for bugs
# From main branch
git checkout main
git pull origin main
git checkout -b feature/your-feature-name
# Or for bug fixes
git checkout -b fix/issue-number-description- Follow code standards (see below)
- Add tests for new functionality
- Update documentation as needed
- Keep changes focused and atomic
# Run all tests
bun test
# Type checking
bun check
# Linting
bun run lint
# Integration tests (if applicable)
bun test packages/mcp-pty/src/__tests__/integration/Follow Conventional Commits specification:
feat: add new PTY monitoring feature
fix: resolve session cleanup issue
docs: update API documentation
test: add integration tests for HTTP transport
refactor: simplify session manager initialization
- Use descriptive title and description
- Link related issues
- Include screenshots for UI changes
- Ensure CI passes
- Strict Mode: All code must pass strict TypeScript checks
- No
any: Use proper typing orunknownwith type guards - No
@ts-ignore: Forbidden except in test files - Prefer
const: Use arrow functions and const declarations - Type Exports: Export types explicitly for better documentation
- Path Aliases: Use
@pkgs/*instead of relative imports - Named Exports: Prefer named exports over default exports
- Type Imports: Use
import typefor type-only imports
// Good
import { PtyManager } from "@pkgs/pty-manager";
import type { Session } from "@pkgs/session-manager";
// Bad
import { PtyManager } from "../pty-manager";
import Session from "../session-manager";- 2-space indentation
- TSDoc comments for public APIs
- Descriptive variable names
- Error handling with proper typing
/**
* Creates a new PTY process with the specified command.
* @param command - Command to execute
* @param options - PTY configuration options
* @returns Promise resolving to PTY process instance
*/
export const createPty = async (
command: string,
options: PtyOptions,
): Promise<PtyProcess> => {
// Implementation
};- Unit Tests: Test individual functions and classes
- Integration Tests: Test package interactions
- Security Tests: Test command validation and security
- E2E Tests: Test complete user workflows
ZERO shared state between tests. All instances must be created and destroyed within test scope:
❌ FORBIDDEN - Describe-scoped variables:
describe("MyTests", () => {
let pty: PtyProcess | null = null; // ❌ SHARED STATE
let manager: PtyManager | null = null; // ❌ Causes races
afterEach(async () => {
if (pty) await pty.dispose();
});
test("test 1", async () => {
pty = new PtyProcess("cmd"); // ❌ Shared reference
});
});✅ REQUIRED - Test-scoped variables with test utilities:
describe("MyTests", () => {
test("test 1", async () => {
await withTestPtyProcess("cmd", async (pty) => {
// pty is isolated to this test, cleaned up after
expect(pty).toBeDefined();
});
});
});Guidelines:
- Use
withTestPtyManager(),withTestPtyProcess(),withTestSessionManager()for all tests - Never declare PTY/Manager/Session variables at describe scope
- Use try/finally in test body if not using utility wrappers
- Each test owns its resources completely
- Cleanup happens immediately after test via callback exit
Each package includes test utilities in src/test-utils.ts:
// Use provided test utilities
import { withTestPtyManager } from "@pkgs/pty-manager";
test("PTY process lifecycle", async () => {
await withTestPtyManager("session-id", async (manager) => {
const { processId } = await manager.createPty("echo hello");
expect(processId).toBeDefined();
// Cleanup happens automatically
});
});Available Utilities:
withTestPtyProcess()- Isolated PTY process per testwithTestPtyManager()- Isolated manager with sessionwithTestPtyManagerAndProcesses()- Manager + multiple processeswithTestSessionManager()- Isolated session tracking
- Aim for >80% code coverage
- Test error conditions and edge cases
- Test security validation thoroughly
- Include performance tests for critical paths
Test command validation scenarios:
test("blocks dangerous commands", () => {
expect(() => normalizeCommand("rm -rf /")).toThrow();
expect(() => normalizeCommand("mkfs.ext4 /dev/sda1")).toThrow();
});- TSDoc: Document all public APIs
- Examples: Include usage examples in complex functions
- Type Definitions: Document complex types and interfaces
- Update feature descriptions
- Add new configuration options
- Include breaking changes
- Update installation instructions
- Update
docs/architecture.mdfor structural changes - Add new diagrams to
docs/diagrams.md - Document new security considerations
- Update integration examples
- All user commands must pass through
normalize-commands - Test security validation thoroughly
- Never bypass security checks
- Document security assumptions
- Validate all file paths
- Use absolute paths for PTY working directories
- Prevent directory traversal attacks
- Sanitize user inputs
- Implement reasonable timeouts
- Limit output buffer sizes
- Monitor resource usage
- Clean up resources properly
- Do not open public issues for security vulnerabilities
- Email maintainers directly
- Provide detailed reproduction steps
- Follow responsible disclosure
- Follow Semantic Versioning
- Update package.json versions
- Update CHANGELOG.md
- Tag releases appropriately
-
Code Quality
- All tests pass
- Code coverage meets requirements
- No linting errors
- Documentation updated
-
Security Review
- Security tests pass
- No new vulnerabilities
- Dependencies audited
-
Release Preparation
- Version numbers updated
- CHANGELOG.md updated
- Release notes prepared
-
Publishing
- Create release tag
- Run automated release workflow
- Verify package publication
The project uses automated releases via GitHub Actions:
- Releases are triggered on main branch merges
- Version bumps follow conventional commits
- Packages are published to npm automatically
- GitHub Issues: For bug reports and feature requests
- GitHub Discussions: For general questions and discussions
- Documentation: Check existing docs first
- TypeScript Errors: Ensure strict mode compliance
- Test Failures: Check test utilities and mocks
- Build Issues: Verify Bun version and dependencies
- Security Tests: Update command validation if needed
We welcome contributions in:
- Core Features: PTY management, session handling
- Security: Command validation, access control
- Performance: Optimization, resource management
- Documentation: Guides, examples, API docs
- Testing: Test coverage, new test scenarios
- Tooling: Build tools, development utilities
Thank you for contributing to mcp-pty! Your contributions help make this project better for everyone.