A Node.js server implementation for the Model Context Protocol (MCP), providing integration with file system operations and MongoDB database operations.
This project contains two MCP servers that enable AI models and tools to interact with external systems through standardized protocols:
- File System Server: Provides file system operations like reading, writing, listing files and creating directories.
- MongoDB Connector Server: Enables interaction with MongoDB databases through operations such as finding, counting, and listing collections.
- Node.js (version 14 or higher)
- MongoDB (for MongoDB connector functionality)
- Clone the repository:
git clone <repository-url>
cd node-mcp-server
- Install dependencies:
npm install
The MongoDB connector uses environment variables for configuration:
MONGODB_URI
- MongoDB connection URI (defaults tomongodb://localhost:27017
)MONGODB_DB
- Database name (defaults todbname
)
Example:
export MONGODB_URI="mongodb://localhost:27017"
export MONGODB_DB="mydatabase"
Run the file system server:
node file-system.js
The server provides the following tools:
-
read_file
- Description: Read file contents from the given path
- Input:
filepath
(string, required)
-
list_files
- Description: List files in a directory
- Input:
dirpath
(string, required)
-
create_file
- Description: Create a new file with the given content
- Input:
filepath
(string, required),content
(string, required)
-
create_folder
- Description: Create a new folder
- Input:
dirpath
(string, required)
Run the MongoDB connector server:
node mongodb-connector.js
The server provides the following tools:
-
mongodb_find
- Description: Get documents from MongoDB collection with optional filter and limit
- Input:
collection
(string, required),filter
(object, optional),limit
(number, optional),sort
(object, optional)
-
mongodb_find_one
- Description: Get a single document from MongoDB collection
- Input:
collection
(string, required),filter
(object, optional)
-
mongodb_count
- Description: Count documents in a collection with optional filter
- Input:
collection
(string, required),filter
(object, optional)
-
mongodb_list_collections
- Description: List all collections in the database
- Input: none
This project implements the Model Context Protocol (MCP), which allows AI models to securely access external tools and data sources. Each server:
- Implements the MCP server interface
- Exposes tools that can be called by AI models
- Handles requests through standard input/output transport
- Returns responses in the expected MCP format
- The file system server has full read/write access to the file system where it runs
- The MongoDB connector has access to the configured database
- Both servers should be deployed in secure environments with appropriate access controls
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a pull request
This project is licensed under the ISC License.