Development setup
Guide
Set up a development checkout of nsf-awards-mcp: prerequisites, npm scripts, project layout, code style and the contribution workflow.
This guide covers a working development checkout of the NSF Awards MCP server: what to install, the npm scripts, where the code lives, the style rules that CI enforces, and how to contribute a change. To install the server only to use it, see Installation instead.
The project is a TypeScript ES module package ("type": "module"). tsc compiles src/ to build/
with module: NodeNext, so relative imports in src/ end in .js.1 The server
is built on @modelcontextprotocol/server and @modelcontextprotocol/node; tests use
@modelcontextprotocol/client.2
Prerequisites
- Node.js 20 or later.
package.jsondeclares"engines": { "node": ">=20" }.2 CI runs on Node 22.3 - npm (the repository has a
package-lock.json; CI installs withnpm ci).3 - Network access to
https://www.research.govonly for the live tests and live smoke checks. The offline suite never calls the real API (see Testing).
First build
git clone https://github.com/tyson-swetnam/nsf-awards-mcp.git
cd nsf-awards-mcp
npm install
npm run build
npm test
These are the steps in the developer guide.1 npm run build writes build/, and
build/index.js is the server entry point that clients run.
npm scripts
Every script below is defined in package.json.2
| Command | Runs | What it does |
|---|---|---|
npm run build |
tsc |
Compile src/ to build/. |
npm run dev |
tsx watch src/index.ts |
Run the server from source and restart on change. stdio by default. |
npm start |
node build/index.js |
Run the built server. |
npm test |
jest |
Offline Jest suite with the NSF client mocked. tests/live is excluded. |
npm run test:watch |
jest --watch |
Offline suite in watch mode. |
npm run test:live |
npm run build && NSF_LIVE=1 jest -c jest.live.config.cjs --runInBand |
Build, then run tests/live against the real NSF API, serially. |
npm run validate:live |
npm run build && node scripts/validate-live.mjs |
Build, then run a fast live smoke check of the built server over stdio. |
npm run lint |
eslint "src/**/*.ts" "tests/**/*.ts" |
Lint source and tests. |
npm run type-check |
tsc --noEmit && tsc -p tsconfig.test.json |
Type-check src/ (tsconfig.json), then src/ and tests/ (tsconfig.test.json). |
npm run format |
prettier --write "src/**/*.ts" "tests/**/*.ts" |
Reformat source and tests. |
npm run format:check |
prettier --check "src/**/*.ts" "tests/**/*.ts" |
Check formatting without writing, as CI does. |
npx jest tests/tools/search-by-pi.test.ts # one test file
npx jest -t "includeCoPIs" # tests whose name matches
npm test -- --coverage # coverage report in coverage/
Running the server locally
src/index.ts serves over stdio unless it gets the --http flag or MCP_TRANSPORT=http.5
npm run dev # stdio, from source
MCP_TRANSPORT=http PORT=3917 npm run dev # Streamable HTTP, from source
curl http://127.0.0.1:3917/health
MCP_TRANSPORT=http PORT=3000 node build/index.js # HTTP from the build: /mcp and /health
LOG_LEVEL=debug npm run dev # log every API request
The HTTP and debug examples come from the developer guide and CLAUDE.md.14 For
the HTTP options (HOST, PORT, MCP_ALLOWED_HOSTS, MCP_ALLOWED_ORIGINS), see
HTTP transport and Configuration.
The repository’s .mcp.json registers the built server with Claude Code as a stdio server named
nsf-awards that runs node build/index.js with NODE_ENV=production and
LOG_LEVEL=info.6 Run npm run build first so that build/index.js exists. For other
clients, see Connecting clients.
Logs never go to stdout. The winston logger sends the levels the code uses (error, warn,
info, debug, verbose) to stderr, because stdout carries the stdio protocol. Winston’s other
default levels, http and silly, are not in that list and would go to stdout, so do not call
logger.http or logger.silly. With NODE_ENV=production, which .mcp.json sets, it also writes
logs/error.log and logs/combined.log (5 MB per file, up to 5 files each) in the working
directory.7 Never use console.log in src/.4
Project layout
src/
index.ts Entry point: stdio by default, HTTP with --http or MCP_TRANSPORT=http
server.ts createServer(): McpServer with SERVER_INFO and SERVER_INSTRUCTIONS,
the 5 tools and 2 resource templates; toCallToolResult()
http.ts createHttpApp() / startHttpServer(): /mcp, GET /health, Host/Origin
checks; httpOptionsFromEnv()
version.ts PACKAGE_NAME and VERSION, read from package.json
client/
nsf-api-client.ts NSFApiClient: NSF API quirks, retries, normalization, cache
tools/
shared.ts ToolDefinition, NotFoundError, shapeAward, statusParams, buildSearchOutput,
pagingHint
search-awards.ts search_nsf_awards (toSearchParams maps tool args to API params)
search-by-institution.ts
search-by-pi.ts piNameParams, and the PI + Co-PI merge (namesPerson, byStartDateDesc)
get-award-details.ts
get-project-outcomes.ts
index.ts exports every tool
types/
mcp-tools.types.ts Zod input schemas (with range checks) and output schemas
nsf-api.types.ts RawNSFAward (as the API sends it), NSFAward (normalized), params
utils/
normalize.ts normalizeAward, parsePerson, toSummary, SUMMARY_FIELDS,
PUBLICATION_FIELDS, pickFields, parseFieldList
date-utils.ts normalizeToNSFDate and friends (calendar strings are time-zone
independent; zoned date-times use the UTC day)
html-utils.ts htmlToText for outcome reports (entities via the entities package)
logger.ts winston logger: stderr, plus logs/ files in production
tests/
client/ tools/ server/ utils/ offline unit tests
live/ live API tests (only run by npm run test:live)
fixtures/ real, trimmed NSF API responses
support/ Jest stand-ins (version.ts)
setup.ts mocks the logger; points the client at a closed port offline
scripts/
validate-live.mjs live smoke run of the built server
probe-nsf-api.sh raw API probes behind the documented API behaviour
check-docs.sh validate the docs/ OKF bundle (--build also builds the Pages site)
docker/ Docker build scripts: build.sh (multi-architecture), build-dev.sh (local)
deployment/ Cloud Run, AWS, nginx and systemd examples, plus install and SSL
helper scripts
This layout follows the developer guide.1 scripts/check-docs.sh checks the
docs/ bundle the way the Pages workflow does,8 scripts/docker/ holds the
image build scripts,9 and deployment/scripts/ holds
install-systemd.sh and setup-ssl.sh.10 For how a request moves through these
files, see Request flow.
Code style
TypeScript. tsconfig.json targets ES2022 with module and moduleResolution set to
NodeNext, strict: true, and these extra checks: noUnusedLocals, noUnusedParameters,
noImplicitReturns and noFallthroughCasesInSwitch. It emits declarations, declaration maps and
source maps into build/, with rootDir: ./src.11 tsconfig.test.json extends it for
type-checking src/ and tests/ together, with module: preserve, moduleResolution: bundler,
noEmit: true and the jest and node types.12
ESLint. ESLint 10 reads the flat config eslint.config.js. It applies @eslint/js recommended and
typescript-eslint’s recommendedTypeChecked rules, with type information from both tsconfig
files.13 Notable rules:
| Rule | Setting |
|---|---|
@typescript-eslint/no-explicit-any |
warn |
@typescript-eslint/no-unused-vars |
error, except names starting with _ |
@typescript-eslint/no-non-null-assertion |
warn (off in tests/**/*.ts) |
@typescript-eslint/require-await |
off in tests/**/*.ts |
no-console |
warn; console.warn and console.error allowed |
prefer-const, no-var |
error |
eqeqeq |
error, always |
curly |
error, all |
ESLint ignores build/, node_modules/, coverage/, *.config.js and *.config.cjs.13
Prettier. .prettierrc sets semicolons on, single quotes, no trailing commas, a print width of
100, 2-space indentation without tabs, arrowParens: always and LF line endings.14
Run npm run format to fix formatting and npm run format:check to check it.
The developer guide also asks for no any and for comments that explain why, not
what.1
Before you push
CI runs on pushes to main, develop and claude/**, on v* tags, and on pull requests to main
and develop. Its quality job gates on type-check, lint, Prettier, the offline tests and the
build, in that order. A security job then fails CI if either
npm audit --omit=dev --audit-level moderate (runtime dependencies) or
npm audit --audit-level high (all dependencies) finds a vulnerability at or above that
severity. Its Snyk scan is advisory (continue-on-error).3 Run the same commands
locally:
npm ci
npm run type-check
npm run lint
npm run format:check
npm test
npm run build
npm audit --omit=dev --audit-level moderate
npm audit --audit-level high
Once the quality and security jobs pass, CI builds the Docker image and smoke-tests it over
stdio and HTTP. Testing
describes each CI job and the live workflows.
Contributing
- Fork the repository, then branch from
main(feat/...,fix/...). - Make the change with tests, and keep
src/andtests/passing type-check, lint and Prettier. - Use conventional commit prefixes:
feat:,fix:,refactor:,docs:,test:,chore:. - Open a pull request against
main. CI must pass.
These steps come from the developer guide.1 CLAUDE.md asks for a summary line of 50 characters or less, a blank line, then a body that says what changed, why, the important technical decisions and the files affected.4
To add or change a tool, follow Adding a tool. To cut a release, follow Releasing.
Resources
The developer guide lists these references.1 For how the server uses the SDK, see Transports and Request flow.
Troubleshooting
| Symptom | Fix |
|---|---|
Cannot find module '@modelcontextprotocol/server' |
rm -rf node_modules && npm install |
MODULE_NOT_FOUND for build/index.js |
Run npm run build. |
Jest fails on import.meta |
Something imports src/version.ts through a path that the moduleNameMapper in jest.config.cjs does not match. Import it as ./version.js or ../version.js. |
| A live test fails but unit tests pass | Compare with the raw API to tell a server bug from an upstream change (see Testing). |
| Need to see API requests | LOG_LEVEL=debug npm run dev. Logs go to stderr. |
These fixes come from the developer guide.1 For problems running the server as a user, see Troubleshooting.
-
Server entry point ↩
-
Project-scoped MCP server registration for Claude Code ↩
-
Winston logger (stderr, plus log files in production) ↩
-
Docs bundle check script (scripts/check-docs.sh) ↩
-
Docker build scripts (scripts/docker/) ↩
-
Deployment helper scripts (deployment/scripts/) ↩
-
TypeScript configuration for src/ ↩
-
TypeScript configuration for src/ and tests/ ↩
-
Prettier configuration ↩