Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/tools/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ export default defineTool({

const isPublic = isPublicArg !== false
const moduleName = name.replace(/-/g, "_")
const modulePath = join(dir, `${moduleName}.py`)

if (existsSync(dir)) {
if (!existsSync(ep.mainPath)) {
return error(`Error: path already exists at ${dir}, but it is not a valid endpoint (__main__.py is missing)`)
}
if (!existsSync(modulePath)) {
return error(`Error: path already exists at ${dir}, but it is not a valid endpoint (module file ${moduleName}.py is missing)`)
}

const existingMain = readFileSync(ep.mainPath, "utf-8")
const existingPublic = existingMain.match(/^#--web\s+(true|false)\s*$/m)?.[1]
Expand Down Expand Up @@ -92,7 +96,7 @@ def main(args):
`

writeFileSync(join(dir, "__main__.py"), mainPy)
writeFileSync(join(dir, `${moduleName}.py`), modulePy)
writeFileSync(modulePath, modulePy)

return text(`Created endpoint at /api/my/${pkg}/${name}\nFiles:\n ${dir}/__main__.py\n ${dir}/${moduleName}.py`)
},
Expand Down
6 changes: 6 additions & 0 deletions tests/secrets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,12 @@ test("action_new reports incompatible existing paths as MCP errors", () => {
assert.equal(incomplete.isError, true)
assert.match(resultText(incomplete), /not a valid endpoint/)

actionNew.handler({ endpoint: "v1/missing-module", public: true })
rmSync("packages/v1/missing-module/missing_module.py")
const missingModule = actionNew.handler({ endpoint: "v1/missing-module", public: true })
assert.equal(missingModule.isError, true)
assert.match(resultText(missingModule), /module file missing_module\.py is missing/)

actionNew.handler({ endpoint: "v1/private-action", public: false })
const visibilityConflict = actionNew.handler({ endpoint: "v1/private-action", public: true })
assert.equal(visibilityConflict.isError, true)
Expand Down
Loading