Installation instructions · Your first server · Download source code (ZIP)
MCP TypeScript SDK helps you write a server that exposes your own actions to Codex. For example, it can read a note from an allowed folder or retrieve information from your application. Codex writes the server code; connecting it and granting data access are separate steps.
Try an existing MCP server first if one fits. Use the SDK for a custom action or logic. It is not a ready-made document search service and does not automatically connect all your files.
How to build a note-reading server
What to install. The current v2 SDK separates server and client packages: @modelcontextprotocol/server builds your server, while @modelcontextprotocol/client builds a client. Codex already acts as the client, so a normal connection does not require writing another one. Older examples using @modelcontextprotocol/sdk belong to v1; do not mix their imports with v2.
For this practice server, use the official tutorial's Node.js 20 or later and ES modules, the format used to import JavaScript files. In a separate project, Codex prepares package.json and installs the server, Zod for input validation and tsx to run TypeScript:
npm install @modelcontextprotocol/server zod tsx
This changes dependencies in the current folder. The assistant first finds the project, checks its package manager and obtains approval. Follow existing project conventions and keep the lockfile. Downloading SDK source code does not replace installing its package.
Example: read one note from the chat.
- Codex creates a separate practice folder with three fictional Markdown notes. It chooses available names and a path without changing your existing knowledge base. Real documents are unnecessary for this first check.
- It writes one reading tool using SDK v2. Input: a relative filename. Output: the file text. Allow only regular Markdown files inside the practice folder. Do not add writing, deletion, command execution or whole-drive access.
- Test an existing file, a missing file, an absolute path, an escape through
..and an outside symlink. Enforce the boundary using resolved paths, not a string prefix alone. Add a file-size limit and a clear refusal so a huge document is not sent accidentally. - After approval, connect to local Codex using STDIO, a process launched by the client, following the MCP connection example. Ask the new tool to read a practice note and compare its response with the file. Code tests and a listed server do not replace this call.
If the server does not respond. With STDIO, send normal logs to stderr, not stdout: stdout carries MCP messages. Check Node availability, the working directory and the launch command from the client itself. A server in a terminal may simply be waiting for input. See the official first-server tutorial.
The process reads files locally but returns their text to the connected assistant. Choose a folder containing information you can share with it. Public HTTP hosting, user sign-in and remote access are separate tasks and are unnecessary here.
What you will have
The result is a small server with one reading action, a limited folder and tested refusals. You are done when a Codex call returns the exact note text and attempts to leave the folder are rejected.
Where it fits. This server is suitable at the document-assistant prototype stage when you need a custom way to retrieve source text. Search, citations, document updates and answer checks still need separate implementation. Use the MCP tool-call check to verify the connection itself.
Update and disconnect. Keep dependency versions and repeat checks after updates. Do not migrate a working v1 server to v2 merely by changing a package name. To disconnect, disable only its MCP entry and stop any remaining process. Keep the source if useful; leave other connections unchanged.
Paste into Codex:
Find the current project and its rules. Create a separate practice MCP server using the official TypeScript SDK that reads Markdown notes only from one folder. Choose an unused folder and create three fictional notes yourself; leave my existing knowledge base and personal documents unchanged.
Read the current README and first-server tutorial at https://github.com/modelcontextprotocol/typescript-sdk. Check Node, the package manager and compatible versions. Use the current stable SDK line without mixing API generations. Show dependencies and wait for my approval before installing. Keep versions and the lockfile.
Implement one read action using a relative filename and a size limit. Do not add writing, deletion, command execution or whole-drive access. Test an existing and missing file, an absolute path, an escape through .., an outside symlink and an oversized file. Enforce the boundary using resolved paths. Send STDIO logs to stderr.
Show the local connection settings and wait for approval. Connect through available tools without changing other servers. Call the note-reading tool from the current Codex client and compare its response with the file. If that client call is unavailable, explain the specific remaining step rather than claiming it passed. Save how to repeat the check and disconnect.
