-
Notifications
You must be signed in to change notification settings - Fork 44
refactor: rename state to session, combine tool registration, and clearer dependencies #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2febc5d
refactor: remove type assertions and simplify state setup
gagik 6c8752b
fix: tests and token refactor
gagik cfc8d89
refactor: re-introduce the server class
gagik 0f03288
chore: add type-powered eslint rules
gagik 0ee6f01
Merge branch 'gagik/strict-eslint' of github.com:mongodb-js/mongodb-m…
gagik 7e0a287
fix: adapt the tst
gagik 97aa690
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into …
gagik 8062288
wip
gagik 2b596fe
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into …
gagik c202de5
Merge branch 'gagik/strict-eslint' of github.com:mongodb-js/mongodb-m…
gagik 8e4f19c
refactor: adapt to latest structure
gagik 2a87387
refactor: adapt to the latest structure
gagik 3c50e08
Merge branch 'main' of github.com:mongodb-js/mongodb-mcp-server into …
gagik e434bae
fix: style
gagik 4d9e651
refactor: make the session close
gagik 94ffeee
Update src/tools/atlas/atlasTool.ts
gagik 0bfd2aa
refactor: align tools naming
gagik 4c96ad9
add changes
gagik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; | ||
import { Server } from "./server.js"; | ||
import logger from "./logger.js"; | ||
import { mongoLogId } from "mongodb-log-writer"; | ||
import { ApiClient } from "./common/atlas/apiClient.js"; | ||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
import config from "./config.js"; | ||
import { State } from "./state.js"; | ||
import { registerAtlasTools } from "./tools/atlas/tools.js"; | ||
import { registerMongoDBTools } from "./tools/mongodb/index.js"; | ||
|
||
export async function runServer() { | ||
const server = new Server(); | ||
try { | ||
const state = new State(); | ||
await state.loadCredentials(); | ||
|
||
const transport = new StdioServerTransport(); | ||
await server.connect(transport); | ||
} | ||
const apiClient = ApiClient.fromState(state); | ||
|
||
const mcp = new McpServer({ | ||
name: "MongoDB Atlas", | ||
version: config.version, | ||
}); | ||
|
||
mcp.server.registerCapabilities({ logging: {} }); | ||
|
||
runServer().catch((error) => { | ||
registerAtlasTools(mcp, state, apiClient); | ||
registerMongoDBTools(mcp, state); | ||
|
||
const transport = new StdioServerTransport(); | ||
await mcp.server.connect(transport); | ||
} catch (error) { | ||
logger.emergency(mongoLogId(1_000_004), "server", `Fatal error running server: ${error}`); | ||
|
||
process.exit(1); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,3 @@ export class State { | |
} | ||
} | ||
} | ||
|
||
const defaultState = new State(); | ||
export default defaultState; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
import { describe, it } from "@jest/globals"; | ||
import { runServer } from "../../src/index"; | ||
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio"; | ||
|
||
// mock the StdioServerTransport | ||
jest.mock("@modelcontextprotocol/sdk/server/stdio"); | ||
// mock Server class and its methods | ||
jest.mock("../../src/server.ts", () => { | ||
return { | ||
Server: jest.fn().mockImplementation(() => { | ||
return { | ||
connect: jest.fn().mockImplementation((transport) => { | ||
return new Promise((resolve) => { | ||
resolve(transport); | ||
}); | ||
}), | ||
}; | ||
}), | ||
}; | ||
}); | ||
import { State } from "../../src/state"; | ||
|
||
describe("Server initialization", () => { | ||
it("should create a server instance", async () => { | ||
await runServer(); | ||
expect(StdioServerTransport).toHaveBeenCalled(); | ||
it("should define a default state", async () => { | ||
const state = new State(); | ||
|
||
expect(state.credentials).toEqual({ | ||
auth: { | ||
status: "not_auth", | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.