Commit 3df5d9f
authored
[MCP] Added read_records tool implementation (#2893)
## Why make this change?
- #2833
One of the main DML tools that will be used is `read_records`, which
will allow the MCP to read the records of an entity based on the needs
of the user.
## What is this change?
- Create the `read_records` tool:
- First it ensures that the MCP has the proper authorization to run the
query
- Then it creates the context with the parameters that were requested by
the user
- Lastly it calls the `SqlQueryEngine` in order to create and run the
query and receive the results
- The `GenerateOrderByLists` function inside the `RequestParser.cs` file
was changed from private to public in order to allow the `read_records`
tool to also use it to generate the proper context for the query.
- Some functions inside of the `SqlResponseHelper.cs` file were changed
to check if the query request comes from the `read_records` tool. This
is done in order to output the correct information, right now the REST
requests can also return a `nextLink` object which gives the API link
necessary to get values in the case that not all of them were shown. We
want to do something similar with the `read_records` tool, however we
only want to return the `after` object which is the parameter that
allows the query to know the exact place where it left from the previous
query. This gets rid of unecessary information that can be found in the
`nextLink` object.
Exceptions thrown when:
1. Entity is empty or null.
2. Parameters are not of the correct type.
3. Parameters are not correctly written.
4. Values inside `orderby` parameter are empty or null. (Note: `orderby`
is an optional value as a whole, but the individual values it contains
need to exist)
5. Not having necessary permissions.
Errors:
1. PermissionDenied - No permssions to execute.
2. InvalidArguments - No arguments provided.
6. InvalidArguments - Some missing arguments.
7. EntityNotFound - Entity not defined in the configuration.
8. UnexpectedError - Any other UnexpectedError.
## How was this tested?
- [ ] Integration Tests
- [ ] Unit Tests
- [x] Manual testing via MCP Inspector
These scenarios were manually tested with the MCP Inspector, as
automated tests are not yet implemented.
### Valid Cases
1. Successful Read
- Provided valid entity and other parameters
- Verified that the received values are the same for MCP as for REST
endpoint
2. Permission Enforcement
- Modified role permissions and verified that access control is enforced
correctly.
3. Parameter Testing
- Provided different valid values for the multiple optional parameters
and ensured they work the same way they do with the REST endpoint.
### Failure Cases
1. Null/Empty Entity Name
- Provided an empty string for entity
- Received InvalidArguments error
2. Invalid Entity Name
- Provided string that is not found in config
- Received InvalidArguments error
3. Invalid Parameters
- Provided non-existent fields for `select` parameter
- Received InvalidArguments error
- Provided invalid string for `filter` parameter
- Received InvalidArguments error
- Provided integer values less than or equal to 0 in the `first`
parameter
- Received InvalidArguments error
- Provided invalid string for `orderby` parameter
- Received InvalidArguments error
- Provided invalid string for `after` parameter
- Received InvalidArguments error
4. Unauthorized Role Context
- Removed or misconfigured role-header
- Received PermissionDenied error
## Sample Request(s)
`{ Entity: Book }`
`{ Select: title,publisher_id }`
`{ First: 3 }`
`{ Orderby: ["publisher_id asc", "title desc"] }`1 parent d6404b3 commit 3df5d9f
4 files changed
Lines changed: 485 additions & 31 deletions
File tree
- src
- Azure.DataApiBuilder.Mcp/BuiltInTools
- Core
- Parsers
- Resolvers
0 commit comments